1
votes

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?

1
When using SPI, always suspect "clock skew". That is, double-check your CPOL (clock polarity) and CPHA (clock phase) settings.Lundin
Looks like it might be sending out too many clock signals. Is the for(loop =0; loop < 20; loop ++) { flashData.TXbuffer[dataCount++] = 0xFF; // dummy bytes } really necessary? Isn't the clocking for the read done in DRV_SPI_BufferAddRead?pm101
Yes, but I added the dummy bytes for testing as it was still giving me 0xFF without the dummy bytes.abdullah

1 Answers

0
votes

Atlast resolved the issue, turns out the SDI port on two different PIC32s were faulty. The third one that we got today worked.

Reminder to others: If your output and subsequent input over MOSI and MISO looks good, your clock looks correct, your pins are being set OK but you're not getting data, you might just have a faulty input connection on your chip.

Configuring the SDI pin as Open drain from Microchip harmony and also declaring the buffer as coherent was helpful atleast in our configuration.