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?
- void SPI_C(int CSi, int di)
- {
- SPI.begin(hCLK, hMISO, hMOSI, CSi);
- digitalWrite(CSi, LOW);
- h = SPI.transfer(0x00);
- l = SPI.transfer(0x00);
- digitalWrite(CSi, HIGH);
- data[di] = (h<<8) | l;
- data[di] >>= 4;
- SPI.end();
- }