2
\$\begingroup\$

I'm trying to setup the STM32L432 MCU for SPI communication (24 MHz, 16 bit data size, master transmit only), using DMA.

The slave device is a 32 channel amplifier chip. I need to send a specific string of bits only once at the start, to setup the registers on the slave device, and then continuously send another string of bits to let the slave know to keep sampling and cycling through its 32 channels, until it receives a stop command or powers down.

I've generated a code using CubeMx, with the appropriate parameters setup. I've been using the HAL_SPI_Transmit_DMA command to send the data. I'm getting the correct SCLK and MOSI signals however am not getting the correct timings between successive SCLK bursts. My two questions are:

  1. The timing between the successive SCLK bursts is too short when Circular DMA transmission is enabled (shown in screenshot)Channel 3 Pink SCLK, Channel 4 Green CS I would need it to be roughly twice as big (about ~200 ns) Where can I control the timing of this? If I enable Normal DMA and put the HAL_SPI_Transmit_DMA command within a while loop I get the opposite problem, the gap between the successive SCLK bursts become too big, about 5 us. I've also tried using software NSS pin control using writepin, however get the same problem as with using the while loop, too big gaps between the data frames.

  2. How could I setup two different DMA profiles to operate withing one script, and call them up when required? I would need this as the bit stream dataTx2 only needs to be sent once so would require DMA to be set to normal, while dataTx would needed to be sent continuously using circular DMA.

The code can be found here: https://github.com/varkong/SPI-DMA-Ver-C/tree/master/Src

Thank you in advance,

varkong

\$\endgroup\$
2
  • \$\begingroup\$ You should be able to call the correspondig HAL functions to reconfigure the DMA at any time, just the Cube won't generate two configurations at the same time for you. \$\endgroup\$
    – JimmyB
    Feb 14, 2017 at 11:42
  • \$\begingroup\$ Btw, if the slave is so timing sensitive, then it's not real SPI you have there. Have you considered to create the required waveform in a different way (PWM, bit banging,...)? \$\endgroup\$
    – JimmyB
    Feb 14, 2017 at 11:44

1 Answer 1

1
\$\begingroup\$

The issue is that the stock SPI DMA stuff ST provides doesn't actually fit your use case here. When you use their SPI driver, it assumes you want to send the data as fast as the bus will support. This means back-to-back transfers, which is what you are seeing.

See if you can look through the reference manual, find how the SPI Tx signal is triggering the DMA, and see if that trigger can be moved to a timer-counter. This is usually possible on full-featured microcontrollers. Then set up a timer-counter to trigger on the period you are interested in.

If you can use the ST HAL driver at all, it'll have to be rewritten to do what you want.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.