cancel
Showing results for 
Search instead for 
Did you mean: 

Simultaneous I2C DMA transfer

I need to control 16 RGB addressable LEDs (48 channels). The only drivers which fit my needs are 24 channel I2C drivers (unfortunately, I couldn't find any suiting SPI drivers ), so I need to use two of them. Since both LED banks will create a common pattern, I2C control packets should come to them with minimal delay.

I am going to use M4 mcu (either F4 or L4).

So my questions (Q) are:

Q1: can I use 2 DMA I2C transfers at the same time if they are configured for different channels?

As far as I understand, DMA transfers only data, so before initiating transfer I need to send

START and device address, and the procedure is going to be as follows:

  • configure I2C/DMA for a first led driver
  • configure I2C/DMA for a second led driver
  • send START and device address to the first led driver
  • initiate transfer to the first led driver
  • send START and device address to the second led driver
  • initiate transfer to the second led driver

If the above is valid -

Q2: It seems like the target identifies first byte after START as address, but acknowledges it as

subsequent data bytes. So is it valid to skip the address sending and include address

as a first byte in a data packet (incrementing data size by 1 and modifying some I2C

functions) ?

Thank you

6 REPLIES 6

Some random remarks, not necessarily answering your questions:

  1. I2C is a multidrop bus, unless the drivers don't support multiple addresses or you need a superfast transfer, you can put them on the same bus
  2. I2C is a pain to implement, both in hardware (thus the implementations are buggy) and in software. You may want to avoid it. I don't believe there are no suitable SPI drivers, search (they are not necessarily "SPI", most simple serial clocked buses are SPI or similar to SPI, though).
  3. 'F4 and 'L4 have two different I2C modules
  4. both I2C incarnations on STM32 implement quite a lot of protocol in hardware, and there's probably no simple way to avoid sending address separately

JW

KnarfB
Principal III

I have an Nucleo-F446RE on my desk and drafted some code for testing. Have no I2C hardware attached, so I2C transfers will not be acknowleged...

MCU runs at 84 MHz. Used quick&dirty HAL for testing, you can later go down low level and assembly roads if you really need to.

Code snippet:

uint32_t tick = __HAL_TIM_GET_COUNTER(&htim2);
 
HAL_I2C_Mem_Write_DMA(&hi2c1, 0x12, 0, I2C_MEMADD_SIZE_8BIT, data2, sizeof data1 );
HAL_I2C_Mem_Write_DMA(&hi2c2, 0x34, 0, I2C_MEMADD_SIZE_8BIT, data2, sizeof data2 );
 
uint32_t tock = __HAL_TIM_GET_COUNTER(&htim2);

Timer tim2 runs as MCU clock counter. tock-tick is 780 cycles, one I2C bit at 400kHz takes 84000000/400000 = 210 clock cycles, so I see no issues. The 0 is the first byte (register address/offet in slave) sent. Again: I had no I2C slaves attached, your mileage may vary.

Yes, I have quite long history of pain related to I2C and try to avoid it whenever I can :(

Unfortunately, existing SPI and SPI-like drivers don't work for me. In most of them PWM frequency is within sound range, and my circuitry is on a microphone board with LEDs spead all over it. To avoid noise in this situation is even bigger pain. Others (like led strings with built-in drivers) don't provide accuracy necessary for specified very flexible light patterns. But I keep looking..

What for F4 and L4 different I2C modules, I believe the I2C/DMA control is pretty much the same, at least for my case. They have different DMA implementation (F4 - dual AHB bus, but for peripheral access it's still only one), but again I don't see that it's going to have big effect.

Please correct me if I am wrong in any of the above.

Thank you for taking time to verify.

Could you please explain the reason you are using HAL_I2C_Mem_Write_DMA() instead of HAL_I2C_Master_Transmit_DMA(&I2cHandle, (uint16_t)I2C_ADDRESS, (uint8_t*)aTxBuffer, TXBUFFERSIZE), which is used in practically all of the related examples?

I understood that for your slaves, the first byte after the slave address is interpreted as internal address/offset as it is for EEPROMs (M24Cxx) etc. Maybe I was wrong. Then, HAL_I2C_Master_Transmit_DMA is the right choice. There should be no big difference in timing.

So I did an extensive search for suitable LED drivers with serial control and unfortunately none of the available ones fit requirements.

Seems like I am going to use TI LP5024 with I2C control.

Now I would like to ask for advice.

My choice of a microcontroller is mostly defined by small non-bga package (going to use UFQFPN48), fash an RAM sizes.

I need to choose between STM32F411/412 and STM32L452. I worked with both lines, but never used I2C on them.

It seems that L4 has more extensive settings which are quite different from F4.

Based on your experience, which one of (F4/L4) would you recommend for I2C DMA application?

Thanks a lot for your help.

GP