M5Core2 icon indicating copy to clipboard operation
M5Core2 copied to clipboard

Timeout on I2C Reads (MPU6886)

Open JasonPittenger opened this issue 8 months ago • 0 comments

Describe the bug

I have my m5Core2 reading from the MPUT6886 in the main loop at a rate of 25Hz (40mS).

#define ONE_SECOND						1000		//mS
#define IMU_SAMPLE_RATE					25
#define IMU_SAMPLE_TIME					ONE_SECOND / IMU_SAMPLE_RATE

void setup() 
{
	Wire1.setTimeOut(50);		//Set I2C timeout to 50mS (instead of default 1000 mS)
	M5.IMU.Init();
}

void loop() 
{
	static uint32_t u32_GyroTime, u32_OldGyroTime, su32_IMUtime;
	
	if(millis() - su32_IMUtime >= IMU_SAMPLE_TIME)
	{//Gather IMU data
		su32_IMUtime += IMU_SAMPLE_TIME;
		u32_GyroTime = micros();
		M5.IMU.getGyroData(&s_IMUdata.f_gyroXraw, &s_IMUdata.f_gyroYraw, &s_IMUdata.f_gyroZraw);
		M5.IMU.getAccelData(&s_IMUdata.f_accXraw, &s_IMUdata.f_accYraw, &s_IMUdata.f_accZraw);
		s_IMUdata.d_dt = (u32_GyroTime - u32_OldGyroTime) / 1e6;
		ProcessIMUdata();
		u32_OldGyroTime = u32_GyroTime;
	}
}

The problem is sometimes there is an error on the read. This results in a 1000mS blocking delay, since the default timeout on I2C is 1000mS. I tried setting the wire timeout to 50 but this doesn't have any affect. Is there any way to set up a shorter timeout period?

To reproduce

I am running Arduino code. My stack is the M5 Core2 with a M5GO Battery Bottom2, a Mini GPS/BDS Unit (AT6558), a COMMU Module Extend RS485/TTL CAN/I2C Port and a Kmeter Unit with Thermocouple Temperature Sensor (MAX31855).

Expected behavior

I expect updated gyro and accel data every 40 mS. I have a data log recording every 100mS.

However, I get gaps of 1 second in the data log. I traced the delay down to the reads from the IMU.

Screenshots

image

Environment

  • OS: Windows 10
  • IDE &IDE Version:
  • Repository Version:

Additional context

No response

Issue checklist

  • [X] I searched for previous reports in the issue tracker
  • [X] My report contains all necessary details

JasonPittenger avatar Nov 17 '23 22:11 JasonPittenger