Unwanted delay before and after SPI transaction
-
- Posts: 20
- Joined: Fri Mar 24, 2017 4:15 am
Unwanted delay before and after SPI transaction
I toggle the CS low, do an SPI transfer, then toggle the CS high. The time between the CS going low and the transfer is 3.24us and 3.7us after the transfer is done and the CS goes high. This really slows down the transfer time. What's causing this delay and is there some way to reduce it?
Re: Unwanted delay before and after SPI transaction
Is there a specific reason your manually toggling CS ?
-
- Posts: 20
- Joined: Fri Mar 24, 2017 4:15 am
Re: Unwanted delay before and after SPI transaction
That’s what the example code did. Is there a faster way?
Re: Unwanted delay before and after SPI transaction
Yes, you can specify the CS pin so it does it automatically.
I just noticed that you posted in the Arduino section, I only use ESP32-IDF. In IDF you can specify the CS pin so it does it for you. Did a little googling and found this.
I just noticed that you posted in the Arduino section, I only use ESP32-IDF. In IDF you can specify the CS pin so it does it for you. Did a little googling and found this.
Code: Select all
#include <SPI.h>
#define HSPI_MISO 12
#define HSPI_MOSI 13
#define HSPI_SCLK 14
#define HSPI_CS 15
static const int spiClk = 240000000; // 1 MHz
SPIClass * hspi = NULL;
char buff[]="Hello Slave\n";
//byte buff[] = {0xAA, 0xBB, 0xAA, 0x01,
0x89, 0xAB, 0xCD, 0xEF};
void setup() {
Serial.begin(9600);
hspi = new SPIClass(HSPI);
hspi->begin();
hspi->begin(HSPI_SCLK, HSPI_MISO, HSPI_MOSI, HSPI_CS); //SCLK, MISO, MOSI, SS
pinMode(HSPI_CS, OUTPUT); //HSPI SS
}
void loop() {
for(int i=0; i<sizeof buff; i++)
{
SPI.transfer(buff[i]);
Serial.println(buff[i]);
}
delay(1000);
}
-
- Posts: 20
- Joined: Fri Mar 24, 2017 4:15 am
Re: Unwanted delay before and after SPI transaction
I’ll test it out and see if that speeds anything up. I found some docs that discussed a 1us delay acquiring a bus but I’m seeing a much larger delay.
-
- Posts: 20
- Joined: Fri Mar 24, 2017 4:15 am
Re: Unwanted delay before and after SPI transaction
This worked for toggling the CS automatically
However, it didn't result in a speedup of the overall SPI process. I measured 3uS before the SPI transfer and 6uS after the SPI transfer worth of delay when the SPI.transfer() call was in a tight loop. Right now, I can get the transfer to occur at around 30ksps which I can make work. Though occasionally, it will have an additional delay which does mess up the timing and I'm not sure what the origin of that is. You can see the spacing of the transfers has wider gaps at various points..
Code: Select all
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI, SPI_SS); // SCK, MISO, MOSI, SS
SPI.setHwCs(true);
Who is online
Users browsing this forum: Bing [Bot] and 33 guests