Part Number: CC1310
Other Parts Discussed in Thread: SYSBIOS, TMP102, TMP006
Tool/software: TI-RTOS
I want to read data from Al3010(ambient sensor) by I2C
However,my code always stock in
I2C_transfer(i2c, &i2cTransaction);
And don't work.
Could help me to know what happen?
Thanks.
Following code is My code .c
#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/drivers/PIN.h>
#include <ti/drivers/I2C.h>
#include "Board.h"
#define TASKSTACKSIZE 640
Task_Struct task0Struct;
Char task0Stack[TASKSTACKSIZE];
int main(void)
{
Bool transferOK;
int i;
uint8_t txBuffer[1];
uint8_t rxBuffer[2];
I2C_Handle i2c;
I2C_Params i2cParams;
I2C_Transaction i2cTransaction;
uint16_t ambientlight;
Board_initGeneral();
Board_initGPIO();
Board_initI2C();
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_400kHz;
i2c = I2C_open(Board_I2C_TMP, &i2cParams);
if (i2c == NULL) {
System_printf("Error Initializing I2C\n");
}
else {
System_printf("I2C Initialized!\n");
}
txBuffer[0] = 0x01;
i2cTransaction.slaveAddress = 0x1c;
i2cTransaction.writeBuf = NULL;
i2cTransaction.writeCount = 0;
i2cTransaction.readBuf= rxBuffer;
i2cTransaction.readCount = 2;
transferOK = I2C_transfer(i2c, &i2cTransaction);
if (!transferOK) { System_printf("I2C Bus fault\n");}
for (i=0;i<=1;i++) {
ambientlight=rxBuffer[0];
System_printf("rxBuffer[0] is %d \n", ambientlight);
ambientlight=rxBuffer[1];
System_printf("rxBuffer[1] is %d \n",ambientlight);
}
I2C_close(i2c);
System_printf("I2C closed!\n");
System_flush();
return (0);
}