This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2640R2F: CC2640r2f

Part Number: CC2640R2F
Other Parts Discussed in Thread: TMP102

Dear sir ,

i am trying to interface EEPROM IC 24C16A using I2C. 

i am getting FF reading from the EEPROM. please check my code & suggest.

/*
* Copyright (c) 2016-2017, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/*
* ======== i2ctmp007.c ========
*/
#include <stdint.h>
#include <stddef.h>
#include <unistd.h>

/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/I2C.h>
#include <ti/display/Display.h>

/* Example/Board Header files */
#include "Board.h"

#define TASKSTACKSIZE 640

#define TMP007_DIE_TEMP 0x01 //0x0000 /* Die Temp Result Register */
#define TMP007_OBJ_TEMP 0x0003 /* Object Temp Result Register */

static Display_Handle display;

/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
unsigned int i;
uint8_t EEDATA0;
uint8_t EEDATA1;
uint8_t txBuffer1[1];
uint8_t txBuffer2[1];
uint8_t txBuffer3[1];
uint8_t rxBuffer[2];
I2C_Handle i2c;
I2C_Params i2cParams;
I2C_Transaction i2cTransaction;

/* Call driver init functions */
Display_init();
GPIO_init();
I2C_init();

/* Open the HOST display for output */
display = Display_open(Display_Type_UART, NULL);
if (display == NULL) {
while (1);
}

/* Turn on user LED */
GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);
Display_printf(display, 0, 0, "Starting the i2ctmp007 example\n");


/* Create I2C for usage */
I2C_Params_init(&i2cParams);
// i2cParams.bitRate = I2C_400kHz;
i2c = I2C_open(Board_I2C_TMP, &i2cParams);
if (i2c == NULL)
{
Display_printf(display, 0, 0, "Error Initializing I2C\n");
while (1);
}
else
{
Display_printf(display, 0, 0, "I2C Initialized!\n");
}

//--------------------------------------------------------------------------------------

/* Point to the T ambient register and read its 2 bytes */
// txBuffer[0] = 0xA0; //EEPROM Device address + Write
// txBuffer[1] = 0xA0;
txBuffer1[0] = 0x55; //EEPROM Word Address
txBuffer2[0] = 0xAA; //EEPROM Data
txBuffer3[0] = 0xA1; //EEPROM Device address + Read

/* Take 20 samples and print them out onto the console */
while(1) {
i2cTransaction.slaveAddress = 0xA0;
usleep(2);
i2cTransaction.writeBuf = txBuffer1;
usleep(2);
i2cTransaction.writeBuf = txBuffer2;
usleep(2);
i2cTransaction.writeBuf = txBuffer3; //
i2cTransaction.writeCount = 1;
usleep(2);

i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 1;


I2C_transfer(i2c, &i2cTransaction);
// if (I2C_transfer(i2c, &i2cTransaction))
// {
/* Extract degrees C from the received data; see TMP102 datasheet */
// temperature = (rxBuffer[0] << 6) | (rxBuffer[1] >> 2);

/*
* If the MSB is set '1', then we have a 2's complement
* negative value which needs to be sign extended
*/
// if (rxBuffer[0] & 0x80) {
// temperature |= 0xF000;
// }
/*
* For simplicity, divide the temperature value by 32 to get rid of
* the decimal precision; see TI's TMP007 datasheet
*/
// temperature /= 32;


EEDATA0 = rxBuffer[0];
EEDATA1 = rxBuffer[1];
Display_printf(display, 0, 0, "Sample %u: %d \n", i, EEDATA0);
Display_printf(display, 0, 0, "Sample %u: %d \n", i, EEDATA1);
// }
// else {
// Display_printf(display, 0, 0, "I2C Bus fault\n");
// }

/* Sleep for 1 second */
sleep(2);
}//End while1


/* Deinitialized I2C */
I2C_close(i2c);
Display_printf(display, 0, 0, "I2C closed!\n");

return (NULL);


}//end main

  • Hi

    I am not familiar with the 24C16A so I do not know what data it expect, but what you are doing with your code is to transmit 1 byte (txBuffer3) to address 0xA0 (i2cTransaction.slaveAddress) , and then you read one byte (readCount = 1). Even if you set readCount to 1 you check both rxBuffer[0] and rxBuffer[1].

    Not sure what you try to do with the following code:

    i2cTransaction.slaveAddress = 0xA0;
    usleep(2);
    i2cTransaction.writeBuf = txBuffer1;
    usleep(2);
    i2cTransaction.writeBuf = txBuffer2;
    usleep(2);
    i2cTransaction.writeBuf = txBuffer3; //
    i2cTransaction.writeCount = 1;
    usleep(2);

    Nothing is sent over I2C before you call teh following:

    I2C_transfer(i2c, &i2cTransaction);
  • Dear sir,

    Thank you for your reply.

    I am trying to write data on EEPROM IC and read back from EEPROM.

  • I understand that. I am just wondering what data you are actually trying to transmit over I2C.

    You are setting the writeBuf to 3 different values (txBuffer1, txBuffer2, and txBuffer3).

    i2cTransaction.slaveAddress = 0xA0;

    usleep(2);

    i2cTransaction.writeBuf = txBuffer1;

    usleep(2);

    i2cTransaction.writeBuf = txBuffer2;

    usleep(2);

    i2cTransaction.writeBuf = txBuffer3; //

    i2cTransaction.writeCount = 1;

    usleep(2);

    Nothing is sent over I2C before you call the following:

    I2C_transfer(i2c, &i2cTransaction);

    and what will be sent then is txBuffer3 to address 0xA0.

    Is this what you want to do?

    If, yes, you could just as well do the following:

    i2cTransaction.slaveAddress = 0xA0;

    i2cTransaction.writeBuf = txBuffer3;

    i2cTransaction.writeCount = 1;

    I2C_transfer(i2c, &i2cTransaction);

    if you want to send 3 bytes to address 0xA0 you should do the following:

    uint8_t txBuffer[] = {0x55, 0xAA, 0xA1};

    i2cTransaction.slaveAddress = 0xA0;

    i2cTransaction.writeBuf = txBuffer;

    i2cTransaction.writeCount = 3;

    I2C_transfer(i2c, &i2cTransaction);

    Siri