cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Communication Flow (Brain Storming)

mrblueblue
Associate II
Posted on August 10, 2016 at 16:04

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

1 REPLY 1
mrblueblue
Associate II
Posted on August 11, 2016 at 04:10

After I send my Start Condition I then send out the Address, Register and Data for an I2C write.

For each of these I am using the I2C_SendData().

For example:

I2C_SendData(I2C3,0xC8);

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

I noticed that in the datasheet that for the TxE flag is says that ''TxE is not set during address phase''.    Should I be using the ADDR flag instead and setting the address of my slave device in I2C_OAR1 (I2C own address)?

Thanks.

-Mike