Max bit size possible to read over SPI?

insanoff
Posts: 15
Joined: Sat Aug 10, 2019 9:10 am

Max bit size possible to read over SPI?

Postby insanoff » Wed Aug 14, 2019 3:26 pm

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

insanoff
Posts: 15
Joined: Sat Aug 10, 2019 9:10 am

Re: Max bit size possible to read over SPI?

Postby insanoff » Fri Aug 16, 2019 10:08 am

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.

ESP_Sprite
Posts: 9043
Joined: Thu Nov 26, 2015 4:08 am

Re: Max bit size possible to read over SPI?

Postby ESP_Sprite » 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.

insanoff
Posts: 15
Joined: Sat Aug 10, 2019 9:10 am

Re: Max bit size possible to read over SPI?

Postby insanoff » Fri Aug 16, 2019 3:35 pm

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?

ESP_Sprite
Posts: 9043
Joined: Thu Nov 26, 2015 4:08 am

Re: Max bit size possible to read over SPI?

Postby ESP_Sprite » 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.

insanoff
Posts: 15
Joined: Sat Aug 10, 2019 9:10 am

Re: Max bit size possible to read over SPI?

Postby insanoff » Sun Aug 18, 2019 4:52 pm

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.

Who is online

Users browsing this forum: No registered users and 61 guests