Part Number: CC3220SF-LAUNCHXL
Other Parts Discussed in Thread: TMP116
Hi,
I am stuck witn a very simple problem using the CC3220SF-LAUNCHXL LP and 24C02 EEPROM over the I2C line. My job is to write a byte of data at internal memory 0x00 of the I2C EEPROM and then read it back and display over the UART log. I went through the TMP116 temp sensor example given in the resource explorer and modified the code in the i2ctmp.c . I am facintg problems on the restart condition generation that is needed to set the internal address of the EEPROM (I2C) using a dummy write.
I am using the ti/drivers/I2C.h and I am using I2C_transfer() function to send and read data from the EEPROM. But the write operation and read operations are unsuccessful. The code is given below, any help is appreciated:
/*
* ======== i2ctmp116.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>
/* Driver configuration */
#include "ti_drivers_config.h"
#define TASKSTACKSIZE 640
/*
* ======== TMP Registers ========
*/
#define _24C64_REG 0x00; // for C64, max reg val is 0b0001111111111111 = 0x1fff
#define _24C64_ADDR 0x50; // appending 0 before the 7 bit address
static Display_Handle display;
/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
uint16_t sample;
uint16_t temperature;
uint8_t txBuffer[3];
uint8_t rxBuffer[10];
I2C_Handle i2c;
I2C_Params i2cParams;
I2C_Transaction i2cTransaction;
/* Call driver init functions */
Display_init();
GPIO_init();
I2C_init();
/* Configure the LED and if applicable, the TMP116_EN pin */
GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
#ifdef CONFIG_GPIO_TMP116_EN
GPIO_setConfig(CONFIG_GPIO_TMP116_EN, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH);
/* 1.5 ms reset time for the TMP116 */
sleep(1);
#endif
/* Open the HOST display for output */
display = Display_open(Display_Type_UART, NULL);
if (display == NULL) {
while (1);
}
/* Turn on user LED */
GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
Display_printf(display, 0, 0, "Starting the i2c24C64 example\n");
/* Create I2C for usage */
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_100kHz;
i2c = I2C_open(CONFIG_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");
}
/* Common I2C transaction setup */
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 2;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 0;
Display_printf(display, 0, 0, "Writing the address 0x00 of EEPROM with data 0x32");
txBuffer[0] = 0x00;
txBuffer[1] = '2';
i2cTransaction.slaveAddress = _24C64_ADDR;
if (!I2C_transfer(i2c, &i2cTransaction))
{
Display_printf(display, 0, 0, "Error. No 24C64 Slave EEPROM found! NACK error");
}
Display_printf(display, 0, 0, "Write successful");
/* Sleep for 1 second */
sleep(1);
/*
* Reading Address set and read data
*/
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 2;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 10;
Display_printf(display, 0, 0, "Setting the address of EEPROM = 0x50");
txBuffer[0] = 0x00;
txBuffer[1] = 0xA1; // Read I2C chip address of the eeprom
i2cTransaction.slaveAddress = _24C64_ADDR;
if (I2C_transfer(i2c, &i2cTransaction))
{
Display_printf(display, 0, 0, " 24C02 Slave EEPROM found!");
for (sample = 0; sample < 10; ++sample)
{
temperature = rxBuffer[sample];
Display_printf(display, 0, 0, "value for read[%d]: %d -- \r", sample, temperature);
}
}
I2C_close(i2c);
Display_printf(display, 0, 0, "I2C closed!");
return (NULL);
}