AnsweredAssumed Answered

Problem on I2C bus

Question asked by Peden.Fabrice on Feb 28, 2013
Latest reply on Apr 12, 2013 by Peden.Fabrice
Hi everybody,

I've got a problem on the I2C bus. I'm trying to read/write an EEPROM (24AA1025 from microchip).
When I'm writing into the EEPROM, I can see I2C sentences on my oscillscope. They're looking good.
To read the EEPROM, I need to do : Start / Control Byte / High Address / Low Address / Start / Control byte / read data.

When I do :  Start / Control Byte / High Address / Low Address, I can see sentences from write and read.

But when I'm doing the read entire procedure (two starts + two control bytes), nothing is now happening.

On the oscilloscope, it seems that the last STOP instruction doesn't work, because I have a 0V voltage. And about the program it's seems to be stopped in  the "while (!I2C_CheckEvent(I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))" of read operation.

If you have any idea that could help me, thank you in advance.
/* Enable the I2C peripheral */
 I2C_GenerateSTART(I2C, ENABLE);
  
 /* Test on SB Flag */
 TimeOut = 100;//TIMEOUT_MAX;
 while (I2C_GetFlagStatus(I2C,I2C_FLAG_SB) == RESET)
 {
     if(TimeOut-- == 0)
     {
         NOP;  
     }
 }
  
 /* Send device address for write */
 I2C_Send7bitAddress(I2C, I2C_EEPROM_ADDRESS, I2C_Direction_Transmitter);
  
 /* Test on ADDR Flag */
 TimeOut = 100;//TIMEOUT_MAX;
 while (!I2C_CheckEvent(I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
 {
     if (TimeOut-- == 0)
     {
         NOP;
     }
 }
 
 I2C_SendData(I2C, adr >> 8);
 TimeOut = 100;
 while ((!I2C_GetFlagStatus(I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(I2C,I2C_FLAG_BTF))) 
 {
     if (TimeOut-- == 0)
     {
       NOP;
     }
 }
  
 I2C_SendData(I2C, adr & 0x00FF);
 TimeOut = 100;
 while ((!I2C_GetFlagStatus(I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(I2C,I2C_FLAG_BTF))) 
 {
     if (TimeOut-- == 0)
     {
       NOP;
     }
 }
      
 /* Send START condition a second time */ 
 I2C_GenerateSTART(I2C, ENABLE);
  
 /* Test on SB Flag */
 TimeOut = 100;//TIMEOUT_MAX;
 while (I2C_GetFlagStatus(I2C,I2C_FLAG_SB) == RESET)
 {
     if(TimeOut-- == 0)
     {
         NOP;  
     }
 }
  
 /* Send IOExpander address for read */
 I2C_Send7bitAddress(I2C, I2C_EEPROM_ADDRESS, I2C_Direction_Receiver);
  
 /* Test on ADDR Flag */
 TimeOut = 100;
 while (!I2C_CheckEvent(I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))  
 {
     if (TimeOut-- == 0)
     {
         return;
     }
 }*
  
 /* Lecture de 128 octets max */
 if(size > 0)
 {
     for(i=0;i<size;i++)
     {        
         tab[i] =  I2C_ReceiveData(I2C);
     }
 }
  
 /* Envoi du signal de Stop */
 I2C_GenerateSTOP(I2C, ENABLE);

Outcomes