RP2040 SPI Chip Select delay time

Hi All!!

I'm using RP2040 pi pico on Arduino Mbed environment.
I hope to control 8 SPI devices by using single SPI bus and 8 Chip Select gpio. The SPI related program is very simple like as bellow.

digitalWrite(dac[ic], LOW); // DAC CS
SPI.transfer(buff, len);
digitalWrite(dac[ic], HIGH);

The time between Chip Select and first SPI_CLK is too longer than my expectation (less than 1us) and I'm looking for the solution but did not find yet. I also changed digitalWrite() function to gpio_clr_mask() to reduce delay time but this is not key impact factor.

Pls advise for me.

Check the datasheet, if the SPI is working, maybe it's the problem in the GPIO, when it operates the CS pin, there is usually a time to write to the pins, try looking for fast writing, usually have to directly manipulate the microcontroller registers that control the pins.

Thanks for your comment and sharing datasheet. I already try direct gpio pin access for chip select and this only reduce total 500ns delay time. There are big delay between CS to CLK around 5 to 7 us.

Try to operate all communication directly too, libraries usually add delays to make the function more adaptable.

1 Like

Hi! All!

I solved this problem by using another SPI library, PicoSPI.

void DAC_Write(int ic, int ch, uint8_t *buff, int len) {
  uint32_t mask;

  mask = 0x01 << dac[ic];
  buff[0] = (buff[0] + ch) & 0xff;
  //digitalWrite(dac[ic], LOW);   // DAC CS
  gpio_clr_mask(mask);            // DAC CS
  PicoSPI0.beginTransaction() ;
  for (int i = 0; i < len; i++)
    PicoSPI0.transfer (buff[i]) ;  
  PicoSPI0.endTransaction() ;
  //SPI.transfer(buff, len);
  //digitalWrite(dac[ic], HIGH);
  gpio_set_mask(mask);
}

Finally I got the more faster SPI access result like as follow.
Thanks to everybody who support me.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.