Skip to main content
Visitor II
July 28, 2006
Question

I2C comm. from STR712 to M24C32

  • July 28, 2006
  • 3 replies
  • 904 views
Posted on July 28, 2006 at 06:09

I2C comm. from STR712 to M24C32

    This topic has been closed for replies.

    3 replies

    Visitor II
    July 19, 2006
    Posted on July 19, 2006 at 08:55

    Hello I am working on a byte read routine.

    I want to read a single byte from the EEprom.

    I found this information in the datasheet for M24C32-:

    ''... The bus master must not acknowledge the byte, and terminates the transfer with a Stop condition.''

    One of the examples of found her in the forum ''Byte read from the external I2C EEPROM mounted on the STR710 demo board'' has a function EEPROM_byte_read:

    /* Send the EEPROM address with LSB bit set */

    I2C_AddressSend (I2C0, M24C08_Block0ADDRESS, I2C_Mode7, I2C_RX);

    while (I2C_FlagStatus (I2C0, DIRECT, I2C_ENDAD)==RESET);

    I2C_FlagClear (I2C0, I2C_ENDAD);

    /*Read 'Buffer_Size' bytes from the EEPROM starting from address 0x00 of Block0

    and place them in Rx_Data[] array */

    /* Generate STOP condition */

    I2C_STOPGenerate (I2C0, ENABLE);

    /* Read byte */

    I2C_Rx_byte = I2C_ByteReceive(I2C0);

    I would have expected something like I2C_AcknowledgeConfig. Other examples, that read more bytes had special cases for the second last byte and the last byte to receive.

    Did I get something wrong?

    Visitor II
    July 19, 2006
    Posted on July 19, 2006 at 09:39

    I have changed the receive function:

    TEepromData EepromByteRead(u16 address)

    {

    TEepromData data;

    u8 buffer[2];

    I2C_Tx_Status status;

    u8 dummy;

    //Generate Start

    I2C_FlagClear (I2C1, I2C_ENDAD);

    I2C_STARTGenerate(I2C1, ENABLE);

    while (I2C_FlagStatus (I2C1,DIRECT,I2C_SB)==RESET);

    //Transmit the address as write mode

    I2C_AddressSend (I2C1,EEPROM_ADDR,I2C_Mode7,I2C_TX);

    //Test the end of address transmission

    while (I2C_FlagStatus (I2C1,DIRECT,I2C_ENDAD)==RESET);

    I2C_FlagClear (I2C1, I2C_ENDAD);

    //Transmit the address de memory

    buffer[0] = address >> 8;

    buffer[1] = address & 0xFF;

    status = I2C_BufferSend (I2C1, buffer,2);

    //Generate Start

    I2C_STARTGenerate(I2C1, ENABLE);

    while (I2C_FlagStatus (I2C1,DIRECT,I2C_SB )==RESET);

    //Transmit the address as read mode

    I2C_AddressSend (I2C1,EEPROM_ADDR,I2C_Mode7,I2C_RX);

    //Test the end of address transmission

    while (I2C_FlagStatus (I2C1,DIRECT,I2C_ENDAD)==RESET);

    I2C_FlagClear (I2C1, I2C_ENDAD);

    //Receive the data

    I2C_AcknowledgeConfig (I2C1, DISABLE);

    data = I2C_ByteReceive (I2C1);

    //Generate Stop

    I2C_STOPGenerate (I2C1, ENABLE);

    I2C_AcknowledgeConfig (I2C1, ENABLE);

    return data;

    }

    To the the function I have used this code:

    u8 i;

    i=0;

    while(i

    EepromByteRead(i);

    EepromByteRead gets stuck somewhere while looping.

    Sometimes I can read several bytes before it locks up,

    sometimes it locks up on the first loop.

    Locking up means the code ist stuck in the ''Generate start'' while loop:

    //Generate Start

    I2C_FlagClear (I2C1, I2C_ENDAD);

    I2C_STARTGenerate(I2C1, ENABLE);

    while (I2C_FlagStatus (I2C1,DIRECT,I2C_SB)==RESET);

    This has happened before (before I added the I2C_AcknowledgeConfig lines).

    Maybe we have to wait for a flag after generating STOP?

    Alexander Mueller

    littleBLUE GmbH

    Visitor II
    July 28, 2006
    Posted on July 28, 2006 at 06:09

    I'm tryin to communicate with a TI DA5571 dac, but my application got stuck in the instruction

    while (I2C_FlagStatus (I2C1,DIRECT,I2C_ENDAD)==RESET);

    I can't see nor the clock neither the address address data out of the micro pins.

    Any suggestions ?

    thanks in advance

    GM