Thursday, 29 August 2019

stm32 - Large delay between I2C messages on STM32F303 - trying to read as fast as possible


I've got a sensor that I'm reading via I2C. My end goal is to be able to maximize the rate at which I can take these readings.


In order to read, I have to write an zero-byte I2C message to the slave to 'wake it', after which I can send a read and receive 2 bytes back with the measurement.


To test my maximum read rate, I set up a basic scheme in which the TX-complete interrupt for the wake message sends out the RX message to the slave, and the RX-complete interrupt sends out another wake-up.


I'm using the HAL libraries, and the relevant code is below:


void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c)
{

//RX finished, wake the sensor back up for a new reading
HAL_I2C_Master_Transmit_IT(&hi2c1,0x28<<1,0,0);
}

void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c)
{
//Wakeup is finished, read measurement into buffer
HAL_I2C_Master_Receive_IT(&hi2c1, 0x28<<1, buffer, 2);
}


Right now I have no other code running, either in the main loop or in these callback functions (I will eventually implement data processing, but I want to benchmark the maximum speed first).


When I look at the I2C Bus with a Logic Analyzer, I see the following:


Logic Analyzer Results - Large Gap Between Messages


There's a fairly large 'gap' between all of my messages, and I don't know what's causing it. There's no computations or anything that should be delaying the chip.


The bus is configured to run at 400 KHz.


Any idea what's causing this delay, and if there's a way to eliminate it to increase my maximum polling speed? Is this just a byproduct of how the I2C protocol needs to work?


Thanks for your help!




No comments:

Post a Comment

arduino - Can I use TI&#39;s cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...