cancel
Showing results for 
Search instead for 
Did you mean: 

I2C master mode for EEPROM no clock for reception

mbeakes
Associate II
Posted on April 04, 2007 at 18:59

I2C master mode for EEPROM no clock for reception

3 REPLIES 3
mbeakes
Associate II
Posted on May 17, 2011 at 09:40

Hi,

I have 2 problems with my I2C communication. First of all, I am using a STR9 with a 24LC256 EEPROM.

1 - When the eeprom ack (9e clock) I saw a ''step'' on the scope. Normally, the eeprom should drive this line to 0 when ack. But the line is going to 2V and right after to 3V. It is like a bus contention.

2- The other problem is when I send a READ operation to the eeprom, the I2C does not generate a CLK. Normally if the ARM9 is the master, it should generate a clock, so that the EEPROM can answer. How can I do this ?

Here is the code (you can also get it with the attached file)

SCU_APBPeriphClockConfig(__GPIO2, ENABLE);

SCU_APBPeriphClockConfig(__I2C0,ENABLE);

SCU_APBPeriphReset(__GPIO2, DISABLE);

/**************************************** I2C EEPROM *************************************************/

GPIO_DeInit(GPIO2);

BSP_GPIOInit.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1; /* PIN_0 = I2C CLK, PIN_1 = I2C DATA */

BSP_GPIOInit.GPIO_Type = GPIO_Type_OpenCollector;

BSP_GPIOInit.GPIO_Direction = GPIO_PinOutput;

BSP_GPIOInit.GPIO_IPConnected = GPIO_IPConnected_Enable;

BSP_GPIOInit.GPIO_Alternate = GPIO_OutputAlt2;

GPIO_Init(GPIO2, &BSP_GPIOInit);

BSP_GPIOInit.GPIO_Pin = GPIO_Pin_2; /* PIN_2 = I2C WP */

BSP_GPIOInit.GPIO_Type = GPIO_Type_PushPull;

BSP_GPIOInit.GPIO_Direction = GPIO_PinOutput;

BSP_GPIOInit.GPIO_IPConnected = GPIO_IPConnected_Enable;

BSP_GPIOInit.GPIO_Alternate = GPIO_OutputAlt1;

GPIO_Init(GPIO2, &BSP_GPIOInit);

I2C_Cmd(I2C0,ENABLE);

GPIO_WriteBit(I2C_WP,Bit_RESET); /* disable WP bit for the EEPROM so we can write to it */

I2C_StructInit(&I2C_Struct);

I2C_DeInit(I2C0);

/* I2C0 Configuration */

I2C_Struct.I2C_GeneralCall = I2C_GeneralCall_Disable;

I2C_Struct.I2C_Ack = I2C_Ack_Enable;

I2C_Struct.I2C_CLKSpeed = 400000;

I2C_Struct.I2C_OwnAddress = 0X04;

I2C_Init(I2C0, &I2C_Struct);

I2C_AcknowledgeConfig(I2C0, DISABLE); /* no ACK for 24LC256 */

I2C_GenerateStart (I2C0, ENABLE);

EV(I2C0, EV5, ( EEPROM_ADDRESS & 0xFE ) ); // Write

EV(I2C0, EV6, 0X00 );

I2C_SendData(I2C0, 0x00); // Flash ADDRESS 0x0000

I2C_SendData(I2C0, 0x00); // Flash ADDRESS 0x0000

I2C_SendData(I2C0, 0xAA); // first data

I2C_SendData(I2C0, 0xBB); // second data to write

I2C_GenerateSTOP (I2C0, ENABLE);

/* --- begin reading at address 0x0000 -----*/

I2C_AcknowledgeConfig(I2C0, DISABLE); /* no ACK for 24LC256 */

I2C_GenerateStart (I2C0, ENABLE);

EV(I2C0, EV5, ( EEPROM_ADDRESS & 0xFE ) ); // Write

EV(I2C0, EV6, 0X00 );

I2C_SendData(I2C0, 0x00); // Flash ADDRESS 0x0000

I2C_SendData(I2C0, 0x00); // Flash ADDRESS 0x0000

I2C_AcknowledgeConfig(I2C0, ENABLE); /* no ACK for 24LC256 */

I2C_AcknowledgeConfig(I2C0, DISABLE); /* no ACK for 24LC256 */

I2C_GenerateStart (I2C0, ENABLE);

EV(I2C0, EV5, ( EEPROM_ADDRESS | 0x01 ) ); // READ

value = I2C_ReceiveData(I2C0); /* data 0xaa */

value = I2C_ReceiveData(I2C0); /* data 0xaa */

I2C_GenerateSTOP (I2C0, ENABLE);

markmcwired9
Associate II
Posted on May 17, 2011 at 09:40

Hi cameleon..!!!

Did you solve this problem ??

I'm about to use a 24LC32 with the STR912, and I'm reading what has been posted about I2C. The example that came with the IAR only explains Master transmission and doesn't say anything about reception.

Hope to hear from you !

Mark.

mbeakes
Associate II
Posted on May 17, 2011 at 09:40

Hi mcwired,

Yes I solved this problem. Just a little trick if you try to debug the I2C, only put the breakpoint after reading the the DR register. Do not trace this line. If you try to trace the reception, you will see the data in the debugger but this data will never be transfer to your variable.