ARM Technical Support Knowledge Articles

SIMULATION OF I2C MEMORY DEVICE

Applies to: uVision Debugger

Answer


Information in this article applies to:


QUESTION

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

ANSWER

Yes, you can simulate an I2C EEPROM using a Signal Function in uVision. You may provide 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

Article last edited on: 2007-04-23 06:03:05

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential