cancel
Showing results for 
Search instead for 
Did you mean: 

I2C1 in DMA mode not reading data continuously (STM32L431)

Kolab
Senior

I am trying to read data from a sensor in the background(using DMA) using I2C. Below the I2C DMA settings on CubeMX. The problem is that it shows a frozen measurement on the debug window although in the blocking mode the measurement floats all the time. Which setting I could have missed?

0693W00000WKU96QAH.png

void QMC7983_read_temp (void){
	uint8_t status_flag = 0xFF;
	uint8_t raw_temp_data[2];
	HAL_I2C_Mem_Read_DMA (&hi2c1, QMC7983_ADDR,STATUS_REG_1,1, &status_flag, 1);
	if((status_flag & 1U>>0)!=1)
		while(1){}
	HAL_I2C_Mem_Read_DMA (&hi2c1, QMC7983_ADDR,TOUT_LSB_REG,1,raw_temp_data, 2);
	temp_meas = (int16_t)(raw_temp_data[1]<<8 |raw_temp_data[0])/100.0;
}
 
 
int main(void)
{
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_TIM1_Init();
  MX_I2C1_Init();
  MX_ADC1_Init();
  QMC7983_config();
  HAL_Delay(100);
  QMC7983_read_temp ();
  while (1)
  {
  }
}

3 REPLIES 3
TDK
Guru

> HAL_I2C_Mem_Read_DMA (&hi2c1, QMC7983_ADDR,STATUS_REG_1,1, &status_flag, 1);

> if((status_flag & 1U>>0)!=1)

Use blocking mode (non-DMA) or wait for the call to complete before using the data that it populates.

> The problem is that it shows a frozen measurement on the debug window although in the blocking mode the measurement floats all the time

What does this mean exactly? measurement floats? shows a frozen measurement?

If you feel a post has answered your question, please click "Accept as Solution".
Kolab
Senior

by frozen I mean the measurement is stuck, as if it reads only one measurement(fixed) no matter if a heat the sensor a little bit.

Float means that the measurement changes constantly in the debugging window(but around a specific reference value)

Kolab
Senior

wait for the call to complete

What do you mean by this?