2013-06-16 03:39 PM
I am trying to use the I2C to read and write to an external 24LC024 EEPROM. I am using a polling method since my DMAs are being used for USART2. I remapped I2C1 to PB8/PB9.
When I read the EEPROM it works fine and I see the correct data. However, when I write it sometimes fails. If I single step through my code (IAR EWARM) it will always write correctly with no errors. However when I let it run freely it will fail waiting for a response from the EEPROM usually when I am sending the data address I want to write to. I have used the settings as suggested in the examples from IAR. What else should I look at? Also, when I read or write I am doing the entire process for each byte. Does anyone have an example of a polling method that is more efficient? For example, setting the eeprom to auto-increment through a page of bytes. Thanks. #stm32f103 #stm32-i2c-eeprom2013-06-17 12:01 AM
Hello,
I wrote for another mcu in the past. Perhaps it would be useful for you. In the code, the pins are defined for a RTC, but this is not important for you. In conclusion both your eeprom and the rtc are using I2C protocol. I hope this helps you./***********************************************************************/
/*
Function : I2C_WriteBit()
Author : Fırat Parlak
Description : Writes one bit on i2c bus.
Bit_Value : The value to write on i2c bus.
Date Created : 2010
Modifications :
*/
/***********************************************************************/
void I2C_WriteBit(unsigned char Bit_Value)
{
RTC_SDA_dir = 1;
RTC_SCL = 0;
if(Bit_Value)
{
RTC_SDA = 1;
}
else
{
RTC_SDA = 0;
}
delay_five_us; //delay 5 us
RTC_SCL = 1;
delay_two_us; //delay 4 us
delay_two_us;
}
/***********************************************************************/
/*
Function : I2C_WriteByte()
Author : Fırat Parlak
Description : Writes one byte on i2c bus.
Tx_Value : The data to write on i2c bus.
Date Created : 2010
Modifications :
*/
/***********************************************************************/
void I2C_WriteByte(unsigned char Tx_Value)
{
unsigned char Bit_cnt;
Bit_cnt = 8;
while(Bit_cnt--)
{
if(Tx_Value&0x80)
{
I2C_WriteBit(1);
}
else
{
I2C_WriteBit(0);
}
Tx_Value <<= 1;
}
I2C_Error = eI2C_Error_None;
if( I2C_ReadBit() )
{
I2C_Error = eI2C_Error_Ack;
}
}
2013-06-17 07:34 AM