cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 I2C with DMA, no ACK after last byte

CKörn.2
Associate II

When reading the I2C bus with DMA it is followed by a NACK.

Do i have to clear it somehow in the DMA1_Stream0_IRQHandler ?

1 ACCEPTED SOLUTION

Accepted Solutions

Hi, CKörn.2,

Yes you have, DMA can not access DTCM.

After changing memory allocation, please inform if your problem is fixed.

You can also refer to this FAQ to see how you change memory in .ld file.

Best Regards,

Ons.

View solution in original post

11 REPLIES 11
CKörn.2
Associate II

0693W000008yZiyQAE.png

CKörn.2
Associate II
HAL_StatusTypeDef I2Cx_ReadBuffer(I2C_HandleTypeDef i2c_handler,
		uint8_t i2c_dev_address, uint8_t *pBuffer,
		uint16_t length) {
	HAL_StatusTypeDef status = HAL_BUSY;
 
	while (HAL_I2C_GetState(&i2c_handler) != HAL_I2C_STATE_READY) {
	}
 
	status = HAL_I2C_Master_Receive_DMA(&i2c_handler, i2c_dev_address,(uint8_t*) &pBuffer[0], length);
 
	/* Check the communication status */
	if (status != HAL_OK) {
		ERROR_VERBOSE_PRINT
		printf("** Reading error i2c device: 0x%x.** \n", i2c_dev_address);
		reset_bus(I2C1_RESET);
	}
 
	return status;
}

Michal Dudka
Senior III

And what's wrong ? It is desirable behavior.

Ons KOOLI
Senior III

Hi CKörn.2,

Can you please refer to this FAQ. Maybe your problem is related to the use of DMA with STM32H7 devices.

Best Regards,

Ons.

CKörn.2
Associate II

Thank you, I already found this FAQ. I disabled ther D-Cache as a quick fix.

CKörn.2
Associate II

Perhaps I have to map the memory directly in the .ld file.

Hi, CKörn.2,

Yes you have, DMA can not access DTCM.

After changing memory allocation, please inform if your problem is fixed.

You can also refer to this FAQ to see how you change memory in .ld file.

Best Regards,

Ons.

Hello,

thank you. Which SRAM section should I use? SRAM with start address 0x38000000 for 64KB?

__attribute__((section(".dma_buffer"))) uint8_t i2c1_TxBuffer[1];
 

Hi CKörn.2,

It really depends on the exact MCU you are using. STM32H7 devices are not all having the same architecture. You can refer to the reference manual that corresponds to your device, under section System Architecture. You have to find the memories that are accessible by DMA (in your case you are probably using DTCM, which is the default memory range used in most of ST projects), choose one of these memories and open your STM32H743XIHX_FLASH.ld file (which is the file used for build) and change the line in Specify the memory areas as described in the following figure:

0693W000008z0AAQAY.pngBest Regards,

Ons.