Page 1 of 1

Max bit size possible to read over SPI?

Posted: Wed Aug 14, 2019 3:26 pm
by insanoff
Hi Folks,

anyone knows what is the maximum word size for ESP32 possible to read over SPI communication?

I'm trying to interface the gyroscope/accelerometer with ESP32 (in Arduino IDE), which requires 32 bit SPI for reading and writing. I can split 32 bits into 4 bytes and write, but how can I read the 32 bit response?

ESP32 has 64 byte SPI FIFO size, but what is the SPI receive register size?

Regards,
Adam

Re: Max bit size possible to read over SPI?

Posted: Fri Aug 16, 2019 10:08 am
by insanoff
Although there is no reply to my question I would like to share my initial thought how 32 bit SPI respond frame can be captured. First the request can be send byte by byte, then the SPI buffer can be read one byte at a time sending dummy loads.

Code: Select all

uint32_t SendRequest(uint32_t Request)
{
    uint32_t Response = 0x00;
    digitalWrite(PIN_CSB, LOW);
    // Send the request in 8-bit sections
    SPI.transfer(Request >> 24);
    SPI.transfer(Request >> 16);
    SPI.transfer(Request >> 8);
    SPI.transfer(Request);
    digitalWrite(PIN_CSB, HIGH);
    delay(1);
    // Capture the response in 8-bit sections
    digitalWrite(PIN_CSB, LOW);
    Response = SPI.transfer(0x00);
    Response = (Response << 8) | SPI.transfer(0x00);
    Response = (Response << 8) | SPI.transfer(0x00);
    Response = (Response << 8) | SPI.transfer(0x00);
    digitalWrite(PIN_CSB, HIGH);
    delay(1);
    return (Response);
}
P.S. It is not an answer.

Re: Max bit size possible to read over SPI?

Posted: Fri Aug 16, 2019 10:57 am
by ESP_Sprite
SPI itself doesn't have the concept of 'word size', it just reads in a stream of bits. The ESP32 hardware then reformats these bits into 32-bit words, but that's just a method of storing information. As you can store a bitstream that is as big as the ESP32's free memory, the bit size is more-or-less infinite.

Re: Max bit size possible to read over SPI?

Posted: Fri Aug 16, 2019 3:35 pm
by insanoff
ESP_Sprite wrote:
Fri Aug 16, 2019 10:57 am
SPI itself doesn't have the concept of 'word size', it just reads in a stream of bits. The ESP32 hardware then reformats these bits into 32-bit words, but that's just a method of storing information. As you can store a bitstream that is as big as the ESP32's free memory, the bit size is more-or-less infinite.
I agree, but AFAIK there is always some frame size limitation. Frame and buffer are different things. So basically, you mean ESP32 can receive 32 bit data in one SPI cycle?

Re: Max bit size possible to read over SPI?

Posted: Sun Aug 18, 2019 5:46 am
by ESP_Sprite
In one transaction (I think you call that a frame; the time when CS is active), you can send/receive any amount of bits, from 1 bit all the way up to 16777215 bits (however, you don't have enough RAM to store the latter amount), and anything in between, with a granularity of 1 bit. As such, 32 bits is possible.

Re: Max bit size possible to read over SPI?

Posted: Sun Aug 18, 2019 4:52 pm
by insanoff
ESP_Sprite wrote:
Sun Aug 18, 2019 5:46 am
In one transaction (I think you call that a frame; the time when CS is active), you can send/receive any amount of bits, from 1 bit all the way up to 16777215 bits (however, you don't have enough RAM to store the latter amount), and anything in between, with a granularity of 1 bit. As such, 32 bits is possible.
Thanks you for the answer. It is good to know that.