Hi,
I´m trying to connect to the LSM6DS33 device via I2C and it has been giving me some problems. My inttention is to do a bluetooth beacon and broadcast a type of interpretation of the values the device gives to me.
The problem is that when I try to read the values with a Periodic Task the LSM6DS33 configuration values dissapear and sometimes the sensor values are zero and sometimes are the correct ones.
static void SimpleBLEBroadcaster_init(void)
{
// ******************************************************************
// N0 STACK API CALLS CAN OCCUR BEFORE THIS CALL TO ICall_registerApp
// ******************************************************************
// Register the current thread as an ICall dispatcher application
// so that the application can send and receive messages.
ICall_registerApp(&selfEntity, &sem);
//The I2C driver initialization
I2C_init();
I2C_Params_init(¶ms);
I2C_Transaction i2cTrans;
uint8_t txBuf[32] = {0}; //Transmit buffer
uint8_t rxBuf[32] = {0}; //Read buffer
handle = I2C_open(Board_I2C, ¶ms);
if(!handle) {
//Error
}
////////////////////////////////LSM6DS33//////////////////
// Configuraciones de gyro y acelerometro
//Acel
// Adress= 0x10 ctrl1
// // 0x80
txBuf[0] = 0x10;
txBuf[1] = 0x80;
i2cTrans.writeCount = 2;
i2cTrans.writeBuf = txBuf;
i2cTrans.readCount = 0;
i2cTrans.readBuf = NULL;
i2cTrans.slaveAddress = 0x6B;
.
.
.
.
}
static void SimpleBLEPeripheral_performPeriodicTask(void)
{
#if 1
//*********************I2C CODE***************************************
struct acel
{
uint16_t x;
uint16_t y;
uint16_t z;
};
struct gyro
{
uint16_t x;
uint16_t y;
uint16_t z;
};
I2C_Transaction i2cTrans;
uint8_t rxBuf[32] = {0}; //Receive buffer
uint8_t txBuf[32] = {0}; //Transmit buffer
struct acel a;
struct gyro g;
handle = I2C_open(Board_I2C, ¶ms);
if(!handle) {
//Error
}
////////////////////////////////LSM6DS33//////////////////
//Read Gyroscope
//Address = 0x22
txBuf[0] = 0x22;
i2cTrans.writeCount = 1;
i2cTrans.writeBuf = txBuf;
i2cTrans.readCount = 6;
i2cTrans.readBuf = rxBuf;
i2cTrans.slaveAddress = 0x6B;
I2C_transfer(handle, &i2cTrans);
g.x= (rxBuf[1]<<8 | rxBuf[0] );
g.y= (rxBuf[3]<<8 | rxBuf[2] );
g.z= (rxBuf[5]<<8 | rxBuf[4] );
.
.
.
I think that the main problem is with the I2C_transfer function. When I debug it step by step it blocks completely, but I´m not sure at all.