Trouble with using I2C to interface with BNO085

Hello,

I am trying to write a library to interface the NRF52840 (Using the DevKit) with a BNO085. The BNO085 uses the Sensor Hub Transport Protocol which modifies the standard I2C library. I've been looking at the Arduino library to copy things over, but have had some trouble with getting the modified I2C working. The Arduino library gets away with simply using the built in I2C commands, I have not had much luck implementing this in Zephyr. Anytime I send out a soft reset I2C command, the I2C write command returns an error. Is my implementation/setup for I2C correct? Thank you.

Config File:

CONFIG_UART_LINE_CTRL=y

CONFIG_STDOUT_CONSOLE=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_CONSOLE_SUBSYS=y
CONFIG_CONSOLE_GETCHAR=y

CONFIG_I2C=y
CONFIG_SMF=y
CONFIG_I2C_NRFX=y

Board File (nrf52840dk_nrf52840.overlay):

&i2c0 {										/* a */
	compatible = "nordic,nrf-twi";			/* b */
	status = "okay";						/* c */
	clock-frequency = <100000>;				/* d */
};	

I2C Setup:

#define BNO085_I2C_ADDRESS (0x4A)

#define I2C_NODE	DT_NODELABEL(i2c0)	
uint32_t i2c_cfg = I2C_SPEED_SET(I2C_SPEED_FAST) | I2C_MODE_CONTROLLER;	
static const struct device *i2c_dev = DEVICE_DT_GET(I2C_NODE);

//...
//Inside an I2C start Function
	printk("I2C is Starting\r\n");

	if (!device_is_ready(i2c_dev)) {
		printk("Error: I2C Device not ready\r\n");
	}
	//Configure I2C
	if (i2c_configure(i2c_dev, i2c_cfg)){
		printk("Error: I2C wont configure\r\n");
	}

I2C Write:

//I2C Interface Functions
static int i2chal_open(sh2_Hal_t *self) {
	printk("Sending Softreset PKT\r\n");
	uint8_t softreset_pkt[] = {5, 0, 1, 0, 1};
	bool success = false;
	for (uint8_t attempts = 0; attempts < 5; attempts++) {
		if (i2c_write(i2c_dev, softreset_pkt, sizeof(softreset_pkt), BNO085_I2C_ADDRESS)) {
			printk("Softreset PKT was succesful\r\n");
			success = true;
			break;
		}
		printk("Softreset PKT Error, Attempt:%i\r\n", attempts);
		k_sleep(K_MSEC(30));
	}
	// if (!success)
	// return -1;
	k_sleep(K_MSEC(300));
	return 0;
}

Parents Reply Children
No Data
Related