cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Connection-Establishing

alexanderlohr9
Associate II
Posted on September 11, 2008 at 12:04

I2C Connection-Establishing

5 REPLIES 5
alexanderlohr9
Associate II
Posted on May 17, 2011 at 09:54

Hi guys,

I have following problem.

I am trying to establish a connection between the both I2C busses located on my STR912F Eva Board.

In my oppinion the command are right but not in the correct order, perhaps you could help. Would be very nice!

The sending of the address is the last event which is occuring, after that the ENDAD flag will not be set and it is waiting in the while loop.

I2C_DeInit(I2C0);

I2C_DeInit(I2C1);

I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;

I2C_InitStructure.I2C_OwnAddress = 0x7F;

I2C_InitStructure.I2C_GeneralCall = I2C_GeneralCall_Disable;

I2C_InitStructure.I2C_CLKSpeed = 100000;

I2C_Init(I2C0, &I2C_InitStructure);

I2C_InitStructure.I2C_OwnAddress = 0xA8;

I2C_Init(I2C1, &I2C_InitStructure);

I2C_GenerateStart(I2C0, ENABLE);

I2C_GenerateStart(I2C1, ENABLE);

while(I2C_GetFlagStatus(I2C0, I2C_FLAG_BUSY) != SET);

I2C_Cmd(I2C0, ENABLE);

I2C_Cmd(I2C1, ENABLE);

while(I2C_GetFlagStatus(I2C0, I2C_FLAG_SB) != SET);

I2C_Send7bitAddress(I2C0, 0xA8, I2C_MODE_TRANSMITTER);

while(I2C_GetFlagStatus(I2C0, I2C_FLAG_ENDAD) != SET);

I2C_SendData(I2C0, 0xFF);

while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BTF) != SET);

test = I2C_ReceiveData(I2C1);

amira1
Associate II
Posted on May 17, 2011 at 09:54

Hello alexander.lohr,

Please find attached a basic example of communication between I2C EEPROM driver with an ST24C02-W EEPROM (with IAR) that can help you to solve your problem. Please refer to the readme file for more details about the example description and the hardware environment.

Best regards,

mirou.

alexanderlohr9
Associate II
Posted on May 17, 2011 at 09:54

Thats a very good example, thank you!

i have changed some things for my project and now i have the following problem:

/* Send EEPROM address for write */

I2C_Send7bitAddress(I2C0, 0xA0, I2C_MODE_TRANSMITTER);

/* Test on EV6 and clear it */

while(!I2C_CheckEvent(I2C0,I2C_EVENT_MASTER_MODE_SELECTED));

It will break on CheckEvent and is still waiting...

I have changed the Send7BitAddress Command from:

I2C_Send7bitAddress(I2C0,EEPROM_ADDRESS, I2C_MODE_TRANSMITTER);

0xA0 is my Address from the DAC which I want to control with the I2C Bus.

Is there anything which I don´t understand?

Thank you very much!

matthew239955_stm1
Associate II
Posted on May 17, 2011 at 09:54

If the slave device fails to ACK your address assertion, the AF flag will be set and the I2C_CheckEvent function will never match the MASTER_MODE_SELECTED parameter. I would scope the bus and see if the slave is responding to the start-address sequence with an ACK. If you are planning on doing anything else with this code, you need to add error recovery in the event that the ACK does not occur.

Matt

robosoft
Associate II
Posted on May 17, 2011 at 09:54

Hi,

There is an error in the I2C_EE_BufferWrite function() when the address is not page alligned. When writing bytes, a ''roll over'' of page can occure...

Luc

[ This message was edited by: robosoft.ontwikkeling on 11-09-2008 15:35 ]