AnsweredAssumed Answered

I2C Communication Flow (Brain Storming)

Question asked by miller.mike.006 on Aug 10, 2016
Latest reply on Aug 11, 2016 by miller.mike.006
All,

For the basic I2C program flow I want to send the start condition, send the address, send the data and then generate the stop condition.  You can see below that after each action I am polling for a flag to move one to the next stage.

My goal is to send an entire I2C transaction of start, address, data, stop and then repeat this over and over so I can look carefully at my scope.

Note:  I am working on a dev board that doesn't have my I2C slave device on it.  I am trying to just see the basic communication out on my scope but I won't be hearing back from the slave device.  This is why on the Send7bitAddress I am checking to see if there was no ACK because there won't be and I know the address should have been sent out.  Just to give the full context I want to get the below code to send out a "full transaction" without the chip I am using on the board for some initial testing.

1.) Does the flow below make sense? It looks like I need one more section of sending out the data (register plus the data).

2.) I was not sure what flag to check after sending the address because this will not impact TxE.    Do the flags that I am checking for make sense?

Thank you for any additional thoughts on this.

 I2C3_Init();

 while(1)
 {

  I2C_GenerateSTART(I2C3, ENABLE);                              
  while( I2C_GetFlagStatus(I2C3,I2C_FLAG_SB) == RESET );          
 
   I2C_Send7bitAddress(I2C3, 0x21, I2C_Direction_Transmitter);     // SEND ADDRESS
   while( I2C_GetFlagStatus(I2C3,I2C_FLAG_AF) == RESET );          

    I2C_SendData(I2C3,0xAA);                                                                  while( I2C_GetFlagStatus(I2C3,I2C_FLAG_TXE) == RESET);    

    I2C_GenerateSTOP(I2C3, ENABLE);

   while( I2C_GetFlagStatus(I2C3,I2C_FLAG_STOPF) == RESET );          

}

-Mike

Outcomes