0

ESP32 has 64 byte SPI FIFO size, but I could not find what is the largest bit size it can receive over SPI?

P.S. I need to interface a sensor, which returns 32 bit response.

EDIT to clarify why I am asking: I am sending 32 bit request by splitting it into 4 bytes, but do not know how to recieve 32 bit response. This function is for sending:

uint32_t SendRequest(uint32_t Request)
{
    uint32_t Response;
    digitalWrite(PIN_CSB, LOW);
    SPI.transfer(Request >> 24);
    SPI.transfer(Request >> 16);
    SPI.transfer(Request >> 8);
    Response = SPI.transfer(Request);
    digitalWrite(PIN_CSB, HIGH);
    return (Response);
}

SPI.transfer() returns the respond after data send completely. Can I read the SPI register?

Datasheet of the sensor: https://www.murata.com/~/media/webrenewal/products/sensor/pdf/datasheet/datasheet_scc2230-e02.ashx?la=en

EDIT to update SendRequest() function:

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);
}
  • 1 byte has 8 bits. 32 bits are 4 bytes. what is the problem? – Juraj Aug 15 at 6:47
  • Why I am asking, because, 32 bit data can be send by splitting it into 4 bytes. But I do not know how to capture full 32 bit respond. I will edit my question to specify. – stardust Aug 15 at 9:06
  • 1
    You don't receive the 32-bit response. You receive the 4 bytes you sent. It's then your job to recombine those bytes into the correct 32-bit value. – Majenko Aug 15 at 9:18
  • 1
    Are you sure you don't first start receiving the response after you have fully transferred your request? Just do four SPI.transfer(0x00) calls after the final request transmit to get the 4 bytes, then, depending on the byte order (little or big endian) of the 32 bit word, shift them back together. It's however not possible to know when your sensor sends the answer because you have provided no datasheet to us. – Maximilian Gerhardt Aug 15 at 16:37
  • 1
    If you only ever receive all 0xFF for the response then MISO might be permanently high. Check that with a multimeter, you might have a wrong wiring – Maximilian Gerhardt Aug 16 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.