Hello I have a problem with simulating an i2c slave device with keil 5.2 and arm cortex m3 LPC1768
I changed the VTREGS of AN153 to simulate the i2c slave (for LPC1768). its completely working when I transmit with completely getting ACK. from address to write the main register of i2c Slave and data byte but In receive mode the slave address get NOT ACK and then I cant read same number that I wrote before ...
the Slave Address is 0xd0 (like DS1307) I've got the simulation like this Sending MASTER 0x68. TRANSMIT x00. 0x0A. (it will work on 0x68(d0 is 8 bit write address) ,0x00 is the controller register,0xA is my data to load on 0x00 register
in receive mode ill get
Receiving MASTER 68! receive (nothing is here , its blank)
my ini code for i2c simulation is (I've copy that from an153 from keil website) :
// Simulation of I2C Memory (Slave) MAP 0,0xFF READ WRITE EXEC // Map User Memory region DEFINE int SADR // Slave Address signal void I2CMEMORY (void) { unsigned long adr; adr = 0; while (1) { wwatch (I2C2_OUT); // Wait for data from Microcontroller while (I2C2_OUT == 0x0100) { // START detected wwatch (I2C2_OUT); // Wait for data from Microcontroller if (I2C2_OUT > 0xFF) continue; if ((I2C2_OUT) != SADR) continue; // test if Slave is addressed I2C2_IN = 0xFF00; // ACK to Microcontroller if (I2C2_OUT & 1) { // Slave Read while (1) { I2C2_IN = _RBYTE(adr); // Read Byte from Memory adr++; wwatch (I2C2_OUT); // Wait for ACK from Microcontroller if (I2C2_OUT != 0xFF00) break; } } else { // Slave Write wwatch (I2C2_OUT); // Wait for data from Microcontroller if (I2C2_OUT > 0xFF) continue; adr = I2C2_OUT | 0; // Set Memory Address I2C2_IN = 0xFF00; // ACK to Microcontroller while (1) { wwatch (I2C2_OUT); // Wait for data from Microcontroller if (I2C2_OUT > 0xFF) break; _WBYTE (adr, I2C2_OUT); // Store Byte in Memory adr++; // Increment Address I2C2_IN = 0xFF00; // ACK to Microcontroller } } } } } SADR = 0xd0 I2CMemory()
I think this code is just for sending from microcontroller am I right??
Please Help me
thanks