Hey everyone,
I am trying to use the BNO055 sensor (a custom breakout) with my project. As I am not using Arduino, I can't use adafruit's library. I sought to use the original library provided by Bosch, but I am not confident my read and write function implementations are correct. Forgive me if there are any silly mistakes as I am still new to this. Any help is greatly appreciated.
Code:
8 bno055_read(u8 addr, u8 reg_addr, u8* reg_data, u8 cnt){
// need to get bus handle + device handle
i2c_master_bus_handle_t bno055_bus_handle;
ESP_ERROR_CHECK(i2c_master_get_bus_handle(BNO055_PORT, &bno055_bus_handle));
// first, send the device address and then the register address
esp_err_t ret = 0;
if(cnt > 1){
// if count is greater than one...
// magic
// unfortunately ESP32 new api doesnt have any read functions that acn do what is specified in the bno055 datasheet
for(int i = 0; i < cnt; i++){
// increment register address and the array value to be able to read more than one byte
// sum to ret because ESP_OK is basically just 0, any other value is an error
// similarly to the BNO055 expected return code
ret += i2c_master_transmit_receive(BNO055_handle, ®_addr, sizeof(reg_addr), reg_data + i, sizeof(*(reg_data + i)), -1);
}
}else{
// else just read once
ret = i2c_master_transmit_receive(BNO055_handle, ®_addr, sizeof(reg_addr), reg_data, sizeof(*reg_data), -1);
}
if(ret != ESP_OK){
ESP_ERROR_CHECK(i2c_master_bus_reset(bno055_bus_handle));
return ret; // anything but 0x00 indicates an error
}
return 0; // if no issues, return 0
}
s8 bno055_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt){
// need to get bus handle + device handle
i2c_master_bus_handle_t bno055_bus_handle;
ESP_ERROR_CHECK(i2c_master_get_bus_handle(BNO055_PORT, &bno055_bus_handle));
// need to write the register address + the actual data...
// size should be cnt + 1 (in bytes)
u8 data_buffer[2];
memcpy(&data_buffer[0], ®_addr, sizeof(reg_addr));
memcpy(&data_buffer[1], reg_data, sizeof(*reg_data));
esp_err_t ret = 0;
for(int i = 0 ; i < (cnt + 1); i++){
ret += i2c_master_transmit(BNO055_handle, &(data_buffer), sizeof(data_buffer), -1);
}
if(ret != ESP_OK){
ESP_ERROR_CHECK(i2c_master_bus_reset(bno055_bus_handle));
return ret;
}
return 0;
}
void bno055_delay_ms(u32 tmsec){
vTaskDelay(pdMS_TO_TICKS(tmsec));
}
BNO055 Bosch sensortec library integration
Jump to
- English Forum
- Explore
- News
- General Discussion
- FAQ
- Documentation
- Documentation
- Sample Code
- Discussion Forum
- ESP32-S31
- Hardware
- ESP-IDF
- ESP-BOX
- ESP-ADF
- ESP-MDF
- ESP-WHO
- ESP-SkaiNet
- ESP32 Arduino
- IDEs for ESP-IDF
- ESP-AT
- ESP IoT Solution
- ESP RainMaker
- Rust
- ESP8266
- Report Bugs
- Showcase
- Chinese Forum 中文社区
- 活动区
- 乐鑫活动专区
- 讨论区
- ESP32-S31 中文讨论版
- 喵伴 中文讨论版
- ESP-IDF 中文讨论版
- 《ESP32-C3 物联网工程开发实战》书籍讨论版
- 中文文档讨论版
- ESP-AT 中文讨论版
- ESP-BOX 中文讨论版
- ESP IoT Solution 中文讨论版
- ESP-ADF 中文讨论版
- ESP Mesh 中文讨论版
- ESP Cloud 中文讨论版
- ESP-WHO 中文讨论版
- ESP-SkaiNet 中文讨论版
- ESP 生产支持讨论版
- 硬件问题讨论
- 项目展示
Who is online
Users browsing this forum: Bing [Bot] and 2 guests
- All times are UTC
- Top
- Delete cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. ESP8266EX and ESP32 are some of our products.
Information
Espressif ESP32 ... Available now!