DMA SPI or no-DMA SPI

Burzum_486
Posts: 1
Joined: Thu Jul 28, 2022 11:05 pm

DMA SPI or no-DMA SPI

Postby Burzum_486 » Thu Jul 28, 2022 11:26 pm

Hello, this question may be not the most clever, but I've read that DMA is not suitable for transfering data <64 bytes but I have it not clear. So, I'll explain my situation and then ask you for your advice.
I'm currently reading data from eight sensors through SPI. I'm currently using the HSPI module and it works fine. But I require a velocity to read them all within a frequency of 2 kHz (or very suitable if I got it to 4 kHz).
That means that the loop where every SPI is read, must be a period of 62~63 μs each Slave device, and actually I'm doing it in a period of ~100 μs for each device.
But also I need that data to be transfer using Wi-Fi and this makes my loop way more "slow".
I'm kinda noob, so, recently I know a little about DMA, but I don't even know if it is a real solution for my problem, the little I read from it, it's that >64 is ideal for its use, but I'm capturing just 16 bytes, meaning that I'm way low from the objective.
I think it would be helpful to use the DMA because then I could use the processor to just print the data out and maybe have a slower data period.
Anyway, here's the code of my SPI protocol, maybe you can help me to get it a bit faster?
  1. void SPI_C(int CSi, int di)
  2. {
  3.   SPI.begin(hCLK, hMISO, hMOSI, CSi);
  4.   digitalWrite(CSi, LOW);
  5.   h = SPI.transfer(0x00);
  6.   l = SPI.transfer(0x00);
  7.   digitalWrite(CSi, HIGH);
  8.   data[di] = (h<<8) | l;
  9.   data[di] >>= 4;
  10.   SPI.end();
  11. }
that function receives the data for the pin defined as Chip Select and an index value "di". As you can see I begin and finish the SPI each time in order to select the Chip Select pin each time, and I store the read data into an array.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 50 guests