04-15-2021 06:55 PM
Hi,
I'm using the template from the BOSCH github to write my I2C bus read and write functions however I can't seem to get it working. I'm using the PSOC generated I2C API's to do the process of bit reading/writing but it seems my I2CMasterSendStart function doesn't return anything. Any help would be great! Thank you
s8 BNO055_I2C_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
{
s32 BNO055_iERROR = 0; // this is the "status" we usually use in our R/W functions
u8 idx;
uint32 timeoutMs = 0; //ms
BNO055_iERROR = imu_bno055_I2CMasterSendStart(dev_addr, imu_bno055_I2C_WRITE_XFER_MODE,timeoutMs);
//^^error occuring here
// Check for BNO055_iERROR before proceeding
BNO055_iERROR = imu_bno055_I2CMasterWriteByte(reg_addr,timeoutMs);
for (idx = 0; (idx < cnt) && (BNO055_iERROR == 0); idx++)
{
BNO055_iERROR = imu_bno055_I2CMasterWriteByte(reg_data[idx],timeoutMs);
//I2C_UART_UartPutString(" bit writing in progress");
}
//I2C_UART_UartPutString(" bit writing done ");
// Check for BNO055_iERROR before proceeding
BNO055_iERROR = imu_bno055_I2CMasterSendStop(timeoutMs);
return (s8)BNO055_iERROR;
}
s8 BNO055_I2C_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
{
s32 BNO055_iERROR = 0; // this is the "status" we usually use in our R/W functions
u8 idx;
uint32 timeoutMs = 0;
BNO055_iERROR = imu_bno055_I2CMasterSendStart(dev_addr, imu_bno055_I2C_WRITE_XFER_MODE,timeoutMs);
// Check for BNO055_iERROR before proceeding
BNO055_iERROR = imu_bno055_I2CMasterWriteByte(reg_addr,timeoutMs);
// Check for BNO055_iERROR before proceeding
BNO055_iERROR = imu_bno055_I2CMasterSendStop(timeoutMs);
BNO055_iERROR = imu_bno055_I2CMasterSendStart(dev_addr, imu_bno055_I2C_READ_XFER_MODE,timeoutMs);
//starts reading the data bit by bit and putting them into a buffer
for (idx = 0; (idx < cnt) && (BNO055_iERROR == 0); idx++)
{
reg_data[idx] = imu_bno055_I2CMasterReadByte(imu_bno055_I2C_ACK_DATA, reg_data, timeoutMs); //stores the byte in an array
}
// Check for BNO055_iERROR before proceeding
//I2C_UART_UartPutString(" bit reading done ");
BNO055_iERROR = imu_bno055_I2CMasterSendStop(timeoutMs);
return (s8)BNO055_iERROR;
}
04-15-2021 11:35 PM
04-16-2021 01:31 AM
Yes I have my dev_addr set to 0x28 and I am still not getting anything. Do you have any recommendations on how I can improve this function?
04-16-2021 06:12 PM
Hello,
Please check whether BNO055 hardware is okay.
5.2 connection diagram i2c.
https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bno055-ds000.pdf
If hardware connection is okay, at least your MCU should send some data and you should be able to check it thru logic analyzer.
Thanks,