I am trying to interface SST26 with Pic32MX470F using Microchip Harmonyv 2.02b SPI drivers. I am able to write/ read correctly according to what I see on my logic analyzer as both MISO and MOSI lines show me the correct data.
The problem I am facing is that in my RX buffer I am not getting the correct data and only see 0xFF in it.
In addition to the read /write functions. I also do global unlock, block erase and write enable before writing anything. I also make sure that SDI line is set as input from harmony pin configuration. My SDI pin is connected to pin45(RPD11/PMCS1/RD11) on pic32.
Below is my implementation.
void Flash1_TestWrite()
{
uint32_t num_of_bytes, loop, dataCount;
flashData.TXbuffer[0] = 0x02; // Write Flash Page1 address 0x0000
flashData.TXbuffer[1] = 0x00;
flashData.TXbuffer[2] = 0x00;
flashData.TXbuffer[3] = 0x00;
dataCount = 4;
for(loop =0; loop < 20; loop ++)
{
flashData.TXbuffer[dataCount++] = 0xAA;
}
num_of_bytes = dataCount; //opcode + address + data
Flash1_WREN(); / /Enable Write
nFlashCS1Off();
Flash1_Write_Buffer_Handle = DRV_SPI_BufferAddWrite(SPIHandle,(SPI_DATA_TYPE *) &flashData.TXbuffer[0], num_of_bytes, 0, 0);
if (DRV_SPI_BUFFER_EVENT_COMPLETE & DRV_SPI_BufferStatus(Flash1_Write_Buffer_Handle))
{
nFlashCS1On();
}
}
voidFlash1_Read( void )
{
switch(flashData.state)
{
uint32_t num_of_bytes, loop, dataCount;
case FLASH1_INIT:
{
nFlashCS1On();
flashData.state = FLASH1_SEND_READ_CMD;
break;
}
case FLASH1_SEND_READ_CMD:
{
flashData.TXbuffer[0] = 0x03; // Read Page
flashData.TXbuffer[1] = 0x00;
flashData.TXbuffer[2] = 0x00; // Address - MSB
flashData.TXbuffer[3] = 0x00; // Address - LSB
dataCount = 4;
for(loop =0; loop < 20; loop ++)
{
flashData.TXbuffer[dataCount++] = 0xFF; // dummy bytes
}
num_of_bytes = dataCount;
nFlashCS1Off();
Flash1_Write_Buffer_Handle = DRV_SPI_BufferAddWrite(SPIHandle, (SPI_DATA_TYPE *) &flashData.TXbuffer[0], num_of_bytes, 0, 0);
flashData.state = FLASH1_WAIT_FOR_REPLY;
break;
}
case FLASH1_WAIT_FOR_REPLY:
{
if(DRV_SPI_BUFFER_EVENT_COMPLETE &
DRV_SPI_BufferStatus(Flash1_Write_Buffer_Handle))
flashData.state = FLASH1_GET_DATA;
break;
}
case FLASH1_GET_DATA:
{
Flash1_Read_Buffer_Handle = DRV_SPI_BufferAddRead( SPIHandle, (SPI_DATA_TYPE *) &flashData.RXbuffer[0], 24, 0, 0);
flashData.state = FLASH1_WAIT_FOR_DATA;
break;
}
case FLASH1_WAIT_FOR_DATA:
{
if(DRV_SPI_BUFFER_EVENT_COMPLETE &
DRV_SPI_BufferStatus (Flash1_Read_Buffer_Handle))
{
nFlashCS1On(); // Assert CS line
flashData.state = FLASH1_READ_COMPLETE;
}
break;
}
case FLASH1_READ_COMPLETE:
{
break;
}
default:
break;
}
return false;
}
Can someone suggest how I can get the correct data in my rx buffer?
for(loop =0; loop < 20; loop ++) { flashData.TXbuffer[dataCount++] = 0xFF; // dummy bytes }
really necessary? Isn't the clocking for the read done inDRV_SPI_BufferAddRead
? – pm101