bno055 PSoC read and write functions

Hello, I am an engineering student at the University of the Fraser Valley and was directed to get into contact with you about accessing the BNO055 data. We are using the Adafruit breakout board with the bno055, and are using a Cypress microcontroller to try and access the data. We are having trouble understanding how to program the read and write functions, and have been trying for over a month with no success. I have read through the bno055.c and bno055_support.c files many times, as well as the datasheet, but we are still stuck. Any help you can provide would be greatly appreciated. Thank you, Fraser Forbes

Best reply by kgoveas

Hi frasics,

Could you try the following snippets for read and write?

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;
	
	BNO055_iERROR = I2C_MasterSendStart(dev_addr, I2C_WRITE_XFER_MODE);
	// Check for BNO055_iERROR before proceeding
	BNO055_iERROR = I2C_MasterWriteByte(reg_addr);
	for (idx = 0; (idx < cnt) && (BNO055_iERROR == 0); idx++)
	{
		BNO055_iERROR = I2C_MasterWriteByte(reg_data[idx]);
	}
	// Check for BNO055_iERROR before proceeding
	BNO055_iERROR = I2C_MasterSendStop();
	
	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;
	
	BNO055_iERROR = I2C_MasterSendStart(dev_addr, I2C_WRITE_XFER_MODE);
	// Check for BNO055_iERROR before proceeding
	BNO055_iERROR = I2C_MasterWriteByte(reg_addr);
	// Check for BNO055_iERROR before proceeding
	BNO055_iERROR = I2C_MasterSendStop();
	
	BNO055_iERROR = I2C_MasterSendStart(dev_addr, I2C_READ_XFER_MODE);
	for (idx = 0; (idx < cnt) && (BNO055_iERROR == 0); idx++)
	{
		reg_data[idx] = I2C_MasterReadByte(I2C_ACK_DATA);
	}
	// Check for BNO055_iERROR before proceeding
	BNO055_iERROR = I2C_MasterSendStop();

	return (s8)BNO055_iERROR;
}
View original
3 replies
Resolved