read from i2c failed 80 percent chance, after couple reboot it works
Posted: Fri Aug 24, 2018 10:36 am
I am trying to connect esp32 to a BNO080 through i2c. The code and bno080 have been tested successfully with Arduino, and there is something weird happening when move to esp32.
The bno080 is connected to 21 22 with 10k pullup from 3.3v. and I am sure the code is fine. but, only one in five times I reset the esp32, it starts to get value from i2c. once it got value, it continues to give value as expected, however, if it doesn't give the value in the first three to five attempt, it will never work, so I will have to reset, until it finally works.
I am using sparkfun_bno080 library, which is tested by many user. So I suspect is there something about i2c in esp32 that i am not aware of. If you have similar experience, please don't hesitate to leave a message, very appreciated. here is the code, I have to write a soft reset loop to get imu working, which is not ideal.
here is serial print , you can see it always works after couple reboot
The bno080 is connected to 21 22 with 10k pullup from 3.3v. and I am sure the code is fine. but, only one in five times I reset the esp32, it starts to get value from i2c. once it got value, it continues to give value as expected, however, if it doesn't give the value in the first three to five attempt, it will never work, so I will have to reset, until it finally works.
I am using sparkfun_bno080 library, which is tested by many user. So I suspect is there something about i2c in esp32 that i am not aware of. If you have similar experience, please don't hesitate to leave a message, very appreciated. here is the code, I have to write a soft reset loop to get imu working, which is not ideal.
Code: Select all
/*
Using the BNO080 IMU
By: Nathan Seidle
SparkFun Electronics
Date: December 21st, 2017
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
Feel like supporting our work? Buy a board from SparkFun!
https://www.sparkfun.com/products/14586
This example shows how to output the i/j/k/real parts of the rotation vector.
https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation
It takes about 1ms at 400kHz I2C to read a record from the sensor, but we are polling the sensor continually
between updates from the sensor. Use the interrupt pin on the BNO080 breakout to avoid polling.
Hardware Connections:
Attach the Qwiic Shield to your Arduino/Photon/ESP32 or other
Plug the sensor onto the shield
Serial.print it out at 9600 baud to serial monitor.
*/
#include <Wire.h>
#include "SparkFun_BNO080_Arduino_Library.h"
BNO080 myIMU;
void(* resetFunc)(void)=0;
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println("BNO080 Read Example");
Wire.begin();
Wire.setClock(400000); //Increase I2C data rate to 400kHz
myIMU.begin();
myIMU.enableRotationVector(10); //Send data update every 50ms
//myIMU.enableDebugging();
float fquate=0;
int count=0;
while(fquate==0){
count++;
Serial.print("trying:");
Serial.println(count);
if(count>5){
count=0;
resetFunc();
}
if (myIMU.dataAvailable() == true){
fquate=myIMU.getQuatI();
Serial.println(fquate);}
delay(100);
}
Serial.println(F("Rotation vector enabled"));
Serial.println(F("Output in form i, j, k, real, accuracy"));
}
void loop()
{
//Look for reports from the IMU
if (myIMU.dataAvailable() == true)
{
float quatI = myIMU.getQuatI();
float quatJ = myIMU.getQuatJ();
float quatK = myIMU.getQuatK();
float quatReal = myIMU.getQuatReal();
float quatRadianAccuracy = myIMU.getQuatRadianAccuracy();
Serial.print(quatI, 2);
Serial.print(F(","));
Serial.print(quatJ, 2);
Serial.print(F(","));
Serial.print(quatK, 2);
Serial.print(F(","));
Serial.print(quatReal, 2);
Serial.print(F(","));
Serial.print(quatRadianAccuracy, 2);
Serial.print(F(","));
Serial.println();
}
}
Code: Select all
Rebooting...
ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:952
load:0x40078000,len:6084
load:0x40080000,len:7936
entry 0x40080310
BNO080 Read Example
trying:1
trying:2
trying:3
trying:4
0.00
trying:5
trying:6
Guru Meditation Error: Core 1 panic'ed (InstrFetchProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x00000000 PS : 0x00060530 A0 : 0x800e6d6e A1 : 0x3ffb1f70
A2 : 0x3ffc286c A3 : 0x3ffc2448 A4 : 0x00000000 A5 : 0x00000000
A6 : 0x00000000 A7 : 0x00000000 A8 : 0x800d0be0 A9 : 0x3ffb1f50
A10 : 0x00000003 A11 : 0x00000001 A12 : 0x0000000a A13 : 0x00000000
A14 : 0x00000002 A15 : 0x00000000 SAR : 0x00000015 EXCCAUSE: 0x00000014
EXCVADDR: 0x00000000 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xffffffff
Backtrace: 0x00000000:0x3ffb1f70 0x400e6d6b:0x3ffb1fa0
Rebooting...
ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:952
load:0x40078000,len:6084
load:0x40080000,len:7936
entry 0x40080310
BNO080 Read Example
trying:1
0.00
trying:2
0.00
trying:3
0.24
Rotation vector enabled
Output in form i, j, k, real, accuracy
0.24,-0.78,-0.54,0.20,0.79,
0.24,-0.78,-0.54,0.20,0.79,
0.24,-0.78,-0.54,0.20,0.79,
0.24,-0.78,-0.54,0.20,0.79,
0.24,-0.78,-0.54,0.20,0.79,
0.24,-0.78,-0.54,0.20,0.79,
0.24,-0.78,-0.54,0.20,0.79,
0.24,-0.78,-0.54,0.20,0.79,