cancel
Showing results for 
Search instead for 
Did you mean: 

problem again with m24 memory with ev5

larsahl
Associate II
Posted on February 28, 2008 at 07:05

problem again with m24 memory with ev5

1 REPLY 1
larsahl
Associate II
Posted on May 17, 2011 at 12:25

If I write 8 bytes in a row the debuging hangs at EV5 check.

Here is my code. I dont know what to do, If I go step by step it works.

I have tried with I2C_DeInit(I2C1); at the stop command in the end but it dosent help.

void I2C_EE_ByteWrite(u8 wByte, u8 WriteAddr)

{

u32 I2C_TimeOut = 0x3FFFF;

int err = 0;

while(err == 0)

{

// Check busy flag

I2C_CheckEvent(I2C1, I2C_FLAG_BUSY);

/* Send STRAT condition */

I2C_GenerateSTART(I2C1, ENABLE);

/* Test on EV5 and clear it */

while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));

/* Send EEPROM address for write */

I2C_Send7bitAddress(I2C1, 0xA0, I2C_Direction_Transmitter);

/* Test on EV6 and clear it */

while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED) && I2C_TimeOut)

{

I2C_TimeOut--;

}

if(I2C_GetFlagStatus(I2C1, I2C_FLAG_AF) != 0x0)

{

err = 0;

}

else

{

err = 1;

}

}

// Clear EV6 by setting again the PE bit

I2C_Cmd(I2C1, ENABLE);

// skicka adress till den minnesposition som data ska skrivas till (2ggr)

/* Send the EEPROM's internal address to write to */

I2C_SendData(I2C1, WriteAddr);

/* Test on EV8 and clear it */

while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));

/* Send the EEPROM's internal address to write to */

I2C_SendData(I2C1, WriteAddr);

/* Test on EV8 and clear it */

while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));

// skriv data

/* Send the byte to be written */

I2C_SendData(I2C1, wByte);

/* Test on EV8 and clear it */

while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));

/* Send STOP condition */

I2C_GenerateSTOP(I2C1, ENABLE);

}