This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Simulating an I2C master

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.

Parents
  • 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)

Reply
  • 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)

Children