Low-level SPI sequential reads give wrong data

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
ScKi_1600301
Level 2
Level 2

I have a simple program for reading the JEDEC information from a serial flash chip using the low-level API.

static void SPI_FlashWriteByte(uint8_t byte)

{

SPI_ClearRxFifo();

SPI_Write(byte);

while (SPI_GetNumInRxFifo() == 0);

SPI_ClearRxFifo();

}

static uint8_t SPI_FlashReadByte()

{

SPI_ClearRxFifo();

SPI_Write(0xFF);

while (SPI_GetNumInRxFifo() == 0);

return SPI_Read();

}

static void SPI_FlashReadJEDEC_Info(uint8_t* mfgID, uint8_t* memoryType, uint8_t* capacityID)

{

CS_FlashEnable();

SPI_FlashWriteByte(0x9F);

*mfgID = SPI_FlashReadByte();

*memoryType = SPI_FlashReadByte();

*capacityID = SPI_FlashReadByte();

CS_FlashDisable();

}

int main(void)

{

     __enable_irq(); /* Enable global interrupts. */

     Cy_SCB_SPI_Init(SPI_HW, &SPI_config, NULL);

     Cy_SCB_SPI_Enable(SPI_HW);

     Trace_Init();

     Trace_Log("\033[2J\033[H"); // Clear screen

     Trace_Log("SPI Test\r\n");

    for(;;)

    {

          uint8_t mfgID, memoryType, capacityID;

          SPI_FlashReadJEDEC_Info(&mfgID, &memoryType, &capacityID);

          Trace_Info("MfgID: 0x%02X, memoryType: 0x%02X, capacityID: 0x%02X", mfgID, memoryType, capacityID);

          CyDelay(100);

    }

}

Which produces the following signals.

D0 = chip select

D1 = SCLK

D2 = MOSI

D3 = MISO (the decoded data at the top is from MISO)

screenshot.jpg

The problem is that each SPI_FlashReadByte() call returns the value that was in the FIFO from the SPI_FlashWriteByte() call.

I've tried using the high-level API with the same results.

0 Likes
1 Solution

Apparently, MISO on this PCB didn't make it to the port pin as another board works just fine.

View solution in original post

0 Likes
2 Replies
ScKi_1600301
Level 2
Level 2

As a clarification, each SPI_ReadByte() returns the 0x04 that was put into the receive fifo from the first write.

0 Likes

Apparently, MISO on this PCB didn't make it to the port pin as another board works just fine.

0 Likes