Skip to main content
Visitor II
October 20, 2024
Question

STM32F1 I2C DMA has no stop bit

  • October 20, 2024
  • 0 replies
  • 542 views

Hi. First time using this forum.

I'm using an STM32F103C8 (genuine, not bluepill clone).

I've easily used DMA to take sensor data and store it in a buffer, this has worked without issue (see below):

 

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
	if (GPIO_Pin == ACC_INT_Pin) // If The INT Source Is ACC
	{
		HAL_I2C_Mem_Read_DMA(&hi2c1, addr_LSM6 << 1, LSM6DS3_ACC_GYRO_OUTX_L_G,
		I2C_MEMADD_SIZE_8BIT, mydata, 12);
	}

}

 

 

 

However, when using the below code, it does not deliver the stop bit, resulting in all future transactions not working.

 

HAL_I2C_Mem_Write_DMA(&hi2c1, addr_LSM6 << 1, LSM6DS3_ACC_GYRO_CTRL9_XL, I2C_MEMADD_SIZE_8BIT, (uint8_t[] ) { 0x38 }, 1);

 

Using the exact same code in blocking mode (as below) works fine.

 

HAL_I2C_Mem_Write(&hi2c1, addr_LSM6 << 1, LSM6DS3_ACC_GYRO_CTRL9_XL,
	I2C_MEMADD_SIZE_8BIT, (uint8_t[] ) { 0x38 }, 1, 1);

 

 Here is a LA shot of the transaction:

triqstar_2-1729419784722.png

As you can see, the SCL line is left high, and the transaction thus does not terminate properly. I should note that the data is received without issue.

 

Below is my cube configuration:

triqstar_3-1729419868264.pngtriqstar_4-1729419879486.png

A similar issue also occurs when trying to read data in some cases, using this code:

 

uint8_t bmp280_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len) {

	uint8_t retval = HAL_I2C_Mem_Read_DMA(&hi2c1, addr, reg, 0x00000001U, buf, len);
	return retval;
}

 

The stop bit is not generated, future transactions don't work as the SCL was not returned to high, though the data from that specific transaction is received without issue.

I should also stress that DMA works perfectly fine for the interrupt-triggered code I showed at the beginning.

 

In summary, my I2C DMA does not generate stop bits, but only for some code. It works fine in other cases. I have no clue what's going on here. Thanks.

    This topic has been closed for replies.