I am developing an application that functions as an I2C slave. To test it, I am trying to write a debug function to simulate the I2C master. With what I have so far, I successfully start I2C communication and receive the first byte. However, after that, the I2C interrupts stop triggering in my application, and the debug function never receives any more bytes.
It seems like the ACK from the master never registers in the application. Here's my debug function:
signal void ReadI2CData() { printf("Sent: Read request to address 0x28\r\n"); I2C1_IN = 0x0100; //Initiate transfer I2C1_IN = 0x28 | 0x01; //from the address of the slave wwatch(I2C1_OUT); // Wait for data from Microcontroller if ( I2C1_OUT == 0xFF00 ) //Slave sent an ACK { printf("Received: ACK\r\n"); } else { printf("Received: %d!\r\n"); return; } while (1) { wwatch(I2C1_OUT); //Wait for data from Microcontroller printf("Received: %d\r\n", I2C1_OUT); I2C1_IN = 0xFF00; //Send the ACK! (This doesn't trigger the interrupt in the application) } }
Any thoughts would be appreciated. Thanks.
Would the errata apply to the simulation mode too? I'm not actually testing it on the hardware yet.
I mostly want to know if my debug function is the proper way to simulate a master continuously reading over I2C, e.g. Is there something else I need to do besides "I2C1_IN = 0xFF00;" to send an ACK from the master?
After I receive the first byte in the debug function, the values of the I2C1 registers are: SR1: 0x0000 SR2: 0x0002 (BUSY = 1) CR1: 0x0401 (PE = 1 and ACK = 1) CR2: 0x0724 (ITBUF EN = 1, ITEVT EN = 1, ITERR EN = 1)
I tried being the master and writing to the simulated slave (http://www.keil.com/support/docs/3325.htm) and again it sends the first byte and then it gets stuck. "I2C1_IN = 0xFF00;" seems like it doesn't register.
Is there another way to test my I2C implementation before hooking up the actual hardware?
Thanks.
Would the errata apply to the simulation mode too? I'm not actually testing it on the hardware yet probably not, but the code should work on the chip as well.