Hi,
I am connecting the LMP91000 to the cc2650 via i2c. When I use the i2c_transfer fucntion the data does not get transfered to the rxBuf array. The value shows to be the '.' character. What is it that I am doing wrong here? Isnt the received data supposed to go to the ruxBuf?
Thanks,
Mustahsin
Code:
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <ti/drivers/I2C.h>
#include <ti/drivers/i2c/I2CCC26XX.h>
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
/* TI-RTOS Header files */
// #include <ti/drivers/I2C.h>
#include <ti/drivers/PIN.h>
// #include <ti/drivers/SPI.h>
// #include <ti/drivers/UART.h>
// #include <ti/drivers/Watchdog.h>
/* Board Header files */
#include "Board.h"
#define TASKSTACKSIZE 512
Task_Struct task0Struct;
Char task0Stack[TASKSTACKSIZE];
/* Pin driver handle */
static PIN_Handle ledPinHandle;
static PIN_State ledPinState;
/*
* Application LED pin configuration table:
* - All LEDs board LEDs are off.
*/
PIN_Config ledPinTable[] = {
Board_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
PIN_TERMINATE
};
/*
* ======== heartBeatFxn ========
* Toggle the Board_LED0. The Task_sleep is determined by arg0 which
* is configured for the heartBeat Task instance.
*/
Void heartBeatFxn(UArg arg0, UArg arg1)
{
while (1) {
Task_sleep((UInt)arg0);
I2C_Handle handle;
I2C_Params i2cParams;
I2C_Transaction i2cTrans;
uint8_t rxBuf[1]; // Receive buffer
uint8_t txBuf[0]; // Transmit buffer
// Configure I2C parameters.
// I2C_Params.I2C_TransferMode=I2C_MODE_CALLBACK;
I2C_Params_init(&i2cParams);
// Initialize master I2C transaction structure
I2CCC26XX_I2CPinCfg pinCfg;
pinCfg.pinSDA = Board_I2C0_SDA0;
pinCfg.pinSCL = Board_I2C0_SCL0;
// i2cParams.custom = &pinCfg;
handle = I2C_open(Board_I2C, &i2cParams);
I2C_open(Board_I2C, &i2cParams);//
i2cTrans.writeCount = 0;
i2cTrans.writeBuf = txBuf;
i2cTrans.readCount = 1;
i2cTrans.readBuf = rxBuf;
i2cTrans.slaveAddress = 0x48;
I2C_transfer(handle, &i2cTrans);//
// uint8_t a ;
I2C_close(handle);// I2C_init();
Task_sleep((UInt)1000);
}
}
/*
* ======== main ========
*/
int main(void)
{
Task_Params taskParams;
/* Call board init functions */
Board_initGeneral();
// Board_initI2C();
// Board_initSPI();
// Board_initUART();
// Board_initWatchdog();
/* Construct heartBeat Task thread */
Task_Params_init(&taskParams);
taskParams.arg0 = 1000;
taskParams.stackSize = TASKSTACKSIZE;
taskParams.stack = &task0Stack;
Task_construct(&task0Struct, (Task_FuncPtr)heartBeatFxn, &taskParams, NULL);
/* Open LED pins */
ledPinHandle = PIN_open(&ledPinState, ledPinTable);
if(!ledPinHandle) {
System_abort("Error initializing board LED pins\n");
}
PIN_setOutputValue(ledPinHandle, Board_LED1, 1);
/* Start BIOS */
BIOS_start();
return (0);
}
screenshot of i2c0 data register
/* XDCtools Header files */#include <xdc/std.h>#include <xdc/runtime/System.h>#include <ti/drivers/I2C.h>#include <ti/drivers/i2c/I2CCC26XX.h>
/* BIOS Header files */#include <ti/sysbios/BIOS.h>#include <ti/sysbios/knl/Task.h>
/* TI-RTOS Header files */// #include <ti/drivers/I2C.h>#include <ti/drivers/PIN.h>// #include <ti/drivers/SPI.h>// #include <ti/drivers/UART.h>// #include <ti/drivers/Watchdog.h>
/* Board Header files */#include "Board.h"
#define TASKSTACKSIZE 512
Task_Struct task0Struct;Char task0Stack[TASKSTACKSIZE];
/* Pin driver handle */static PIN_Handle ledPinHandle;static PIN_State ledPinState;
/* * Application LED pin configuration table: * - All LEDs board LEDs are off. */PIN_Config ledPinTable[] = { Board_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, PIN_TERMINATE};
/* * ======== heartBeatFxn ======== * Toggle the Board_LED0. The Task_sleep is determined by arg0 which * is configured for the heartBeat Task instance. */Void heartBeatFxn(UArg arg0, UArg arg1){ while (1) { Task_sleep((UInt)arg0); I2C_Handle handle; I2C_Params i2cParams; I2C_Transaction i2cTrans; uint8_t rxBuf[1]; // Receive buffer uint8_t txBuf[0]; // Transmit buffer // Configure I2C parameters. txBuf[0]='b'; // I2C_Params.I2C_TransferMode=I2C_MODE_CALLBACK; I2C_Params_init(&i2cParams);
// Initialize master I2C transaction structure I2CCC26XX_I2CPinCfg pinCfg; pinCfg.pinSDA = Board_I2C0_SDA0; pinCfg.pinSCL = Board_I2C0_SCL0; // i2cParams.custom = &pinCfg; handle = I2C_open(Board_I2C, &i2cParams); I2C_open(Board_I2C, &i2cParams);//
i2cTrans.writeCount = 0; i2cTrans.writeBuf = txBuf;
i2cTrans.readCount = 1; i2cTrans.readBuf = rxBuf; i2cTrans.slaveAddress = 0x49; I2C_transfer(handle, &i2cTrans);// uint8_t a ;
I2C_close(handle);// I2C_init(); Task_sleep((UInt)1000); }}
/* * ======== main ======== */int main(void){ Task_Params taskParams;
/* Call board init functions */ Board_initGeneral(); // Board_initI2C(); // Board_initSPI(); // Board_initUART(); // Board_initWatchdog();
/* Construct heartBeat Task thread */ Task_Params_init(&taskParams); taskParams.arg0 = 1000; taskParams.stackSize = TASKSTACKSIZE; taskParams.stack = &task0Stack; Task_construct(&task0Struct, (Task_FuncPtr)heartBeatFxn, &taskParams, NULL);
/* Open LED pins */ ledPinHandle = PIN_open(&ledPinState, ledPinTable); if(!ledPinHandle) { System_abort("Error initializing board LED pins\n"); }
PIN_setOutputValue(ledPinHandle, Board_LED1, 1);
/* Start BIOS */ BIOS_start();
return (0);}