cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f7 I2C master transmission using DMA does not work

SeyyedMohammad
Senior III

The problem is the code:

  HAL_I2C_Master_Transmit_DMA (&hi2c1, (uint16_t)(MCP4725A0_ADDR_A00<<1), (uint8_t *)buffer, 2);

Though it returns `HAL_OK` but causes no response from slave device, but other version of this code: interruptive or blocking are works perfectly (Slave is DAC [MCP4725](https://ww1.microchip.com/downloads/en/DeviceDoc/22039d.pdf) and master is [STM32f746ng](https://www.st.com/resource/en/datasheet/stm32f746ng.pdf)).

I've found the heart codes actually executing in this bad :( DMA code:

  HAL_DMA_Start(&hdma_i2c1_tx, buffer, (uint32_t)&(hi2c1.Instance->TXDR), 2);

  hi2c1.Instance->CR1 |= I2C_CR1_TXDMAEN;

  I2C_TransferConfig(&hi2c1, (MCP4725A0_ADDR_A00<<1), (uint8_t)2, I2C_AUTOEND_MODE, I2C_GENERATE_START_WRITE);

After running these code debugger shows the state of Both DMA and I2C are busy there is no new data on `TXDR`, and `TXIS` and `TXE` are both set. I think it means DMA does not respond to I2C `TXIS` despite `TXDMAEN` has been set.

Note: `buffer` is placed at `0x2004,FFF4`. Which is located on 0x2004,C000-0x2004,FFFF -> <<SRAM2 (16 KB)>> on the <<512-Mbyte Block 1 SRAM>> 0x2000,0000-0x3FFF,FFFF

As [STM32f7 Reference manual](https://www.st.com/resource/en/reference_manual/rm0385-stm32f75xxx-and-stm32f74xxx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf) told, I2C `TXIE` does not require to be set and setting `TXDMAEN` will cause to if `TXIS` set by hardware then rise request to `DMA` for data transfer from memory to I2C peripheral `TXDR` and this copying process cause to decrease embedded counter of I2C and after counter reaches 0 the transmission will end.

System configuration:

--------------

DMA is memory incremental byte sized in normal mode without FIFO using DMA1Stream6 memory to peripheral and the flow controller is DMA(!).

I2C1 is in fast mode 7bit address, clock no stretch disabled and general call address detection enabled.

HCLK clock is 150MHz on Power Regulator voltage scale 2. All catches are disabled and works on AXI flash interface.

The NVIC is not important because even the first transfer does not occur.

CUBE generated code comparison with HAL example for stm32f746-discovery

-------------------

HAL_I2C_Master_DMA() was exactly the same but the difference was in MspInit() I2C GPIO in example was set to PULLUP but NoPull in cube. (It must be not important since interruptive version worked). The last difference was Msp of example first enabled clock of GPIO, I2C and DMA then started to initialize their structure, but cube first enabled GPIO's clock then initiated it then enabled I2C Clock then initiated DMA then enabled DMA clock.

1 ACCEPTED SOLUTION

Accepted Solutions
SeyyedMohammad
Senior III
5 REPLIES 5
Amel NASRI
ST Employee

Hi @SeyyedMohammad​ ,

Based on the comparison you made between CubeMX generated code and the code in the examples, I confirm that it is recommended to configure GPIO (clock & initialization) before enabling I2C clock.

DMA clock has to be enabled before I2C initialization as well.

I add @Khouloud OTHMAN​  as STM32CubeMX expert to investigate more the code generated with STM32CubeMX. It is relevant to let us know the tool's version you are using and it will be helpful if you can share an .ioc file.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hello @SeyyedMohammad​ ,

First let me thank you for having reporting.

Could you please share the.ioc file of your project for further check from my side ?

Thanks in advance.

Khouloud.

SeyyedMohammad
Senior III

Hi @Khouloud OTHMAN​ 

And hi @Amel NASRI​ 

Answer is posted here:

STM32f7 I2C master transmission using DMA does not work - Electrical Engineering Stack Exchange

SeyyedMohammad
Senior III

@Khouloud OTHMAN​  @Amel NASRI​ 

Hello dear, I have question about QuadSPI that I've asked stm32 - stm32f7 QSPI (QUADSPI) in indirect mode can't read/write on NOR flash memory - Electrical Engineering Stack Exchange

Could you please tell me your opinion about it?

Hi @SeyyedMohammad​ ,

Thanks for sharing the link, will have a look. But it will be better to put a description in a new thread here on ST Community. You will have more chance to get an answer by our Experts here.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.