Keil Logo

µVISION DEBUGGER: SIMULATION OF I2C MEMORY DEVICE


Information in this article applies to:

  • µVision Version 3
  • RealView Microcontroller Development Kit

QUESTION

I would like to simulate a I2C EEPROM that is connected to the I2C peripheral of a Microcontroller. Is this possible?

ANSWER

Yes, you can simulate an I2C EEPROM using a Signal Function in µVision. You must identify the memory that is mapped into the address space of the ARM microcontroller. The following example shows a script that is ready-to-run for Luminary Cortex-M3 based microcontrollers.

// Simulation of I2C Memory (Slave)

MAP 0x70000000, 0x7000FFFF READ WRITE        // Map User Memory region

DEFINE int SADR                              // Slave Address

signal void I2CMEMORY (void) {
  unsigned long adr;

  adr = 0x70000000;
  while (1) {
    wwatch (I2C_OUT);                        // Wait for data from Microcontroller
    while (I2C_OUT == 0x0100) {              // START detected
      wwatch (I2C_OUT);                      // Wait for data from Microcontroller
      if (I2C_OUT > 0xFF) continue;
      if ((I2C_OUT >> 1) != SADR) continue;  // test if Slave is addressed
      I2C_IN = 0xFF00;                       // ACK to Microcontroller
      if (I2C_OUT & 1) {                     // Slave Read
        while (1) {
          I2C_IN = _RBYTE(adr);              // Read Byte from Memory
          adr++;                             // Increment Address
          wwatch (I2C_OUT);                  // Wait for ACK from Microcontroller
          if (I2C_OUT != 0xFF00) break;
        }
      }
      else {                                 // Slave Write
        wwatch (I2C_OUT);                    // Wait for data from Microcontroller
        if (I2C_OUT > 0xFF) continue;
        adr = I2C_OUT + 0x70000000;          // Set Memory Address
        I2C_IN = 0xFF00;                     // ACK to Microcontroller
        while (1) {
          wwatch (I2C_OUT);                  // Wait for data from Microcontroller
          if (I2C_OUT > 0xFF) break;
          _WBYTE (adr, I2C_OUT);             // Store Byte in Memory
          adr++;                             // Increment Address
          I2C_IN = 0xFF00;                   // ACK to Microcontroller
        }
      }
    }
  }
}


SADR = 0x2A
I2CMemory()     // Start the signal function

You may automatically execute this script when you start the debugger by entering in under Project - Options for Target - Debug - Initialization File.

MORE INFORMATION

SEE ALSO

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Thursday, September 22, 2016


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.