- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Apparently, MISO on this PCB didn't make it to the port pin as another board works just fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As a clarification, each SPI_ReadByte() returns the 0x04 that was put into the receive fifo from the first write.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Apparently, MISO on this PCB didn't make it to the port pin as another board works just fine.