5 years, 9 months ago.

SPI burst read - seeing wait between two reads

/media/uploads/JigneshSoftnautics/spi-bulk-read.jpg Hi All,

HW board - Nucleo-F401RE

I am trying to perform bulk read - trying to read 2 bytes - address 0 & 1.

On the scope, i see that after writing address, around 7 uSec. gap and after reading 1st byte (address 0), again 7 usec. gap after which it reads data from address 1. Data read is correct but it takes longer due to 7 usec gap between each data read.

Following is code snippet used to read from SPI:

cs = 0;

write address from where to read device.write(read_cmd);

read data by writing 0x00 read_data[0] = device.write(0x00); read_data[1] = device.write(0x00);

cs = 1;

I was hoping that bulk data should be read continuously. please suggest to fix above issue.

Appreciate help in advance. Regards, Jignesh

I solved the issue by implementing bit bang as following:

uint8_t SPIBurstWriteRead(uint8_t data) { Check if old data is transmitted and tx buffer is ready for new data while ((SPI1->SR & SPI_SR_TXE) == 0); SPI1->DR = data;

wait till RX buffer ready while ((SPI1->SR & SPI_SR_RXNE) == 0); return SPI1->DR; }

this may help others in future...

posted by Jignesh Shah 13 Feb 2019

1 Answer

5 years, 9 months ago.

Check this out, it might help:

https://os.mbed.com/questions/2408/16-us-gap-between-sending-SPI-data/

Thank you for your prompt response. BurstSPI supports only write, i have to read in burst. is there any other than implementing HAL? It would make code less portable. i found earlier overloaded write function was there which was taking four arguments - write buff, write count, read buff and read count. is it removed in lastest mbed?

posted by Jignesh Shah 12 Feb 2019

I would look at the read part and compare with the BurstSPI write perhaps there are delays there that you could modify. When you say Mbed is that OS2 or OS5.

posted by Paul Staron 12 Feb 2019

BurstSPI library does not read back after write to speed up write. In my case, I can't avoid reading back since I have to read data. So unfortunately, BurstSPI can't be my reference code. [However, i still referred it earlier] To answer your question, I am using latest mbed - mbed OS5.

posted by Jignesh Shah 12 Feb 2019