• AVR Freaks

Hot!DRV_SPI_BufferAddRead always returns 0xFF

Author
azaman
Starting Member
  • Total Posts : 43
  • Reward points : 0
  • Joined: 2018/06/14 05:08:52
  • Location: 0
  • Status: offline
2019/04/25 06:09:56 (permalink)
0

DRV_SPI_BufferAddRead always returns 0xFF

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 below read / write functions. I also do global unlock, block erase and  write enable before writing anything. I have also attached the output of my logic analyzer and my harmony spi configuration. I also make sure that SDI line is set as input from harmony pin configuration.
Can someone suggest how I can get the correct data in my rx buffer?
 
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;
}

 
post edited by azaman - 2019/04/25 06:12:12

Attached Image(s)

#1

5 Replies Related Threads

    nigelwright7557
    Super Member
    • Total Posts : 270
    • Reward points : 0
    • Joined: 2006/11/06 08:15:51
    • Location: 0
    • Status: online
    Re: DRV_SPI_BufferAddRead always returns 0xFF 2019/04/25 06:13:34 (permalink)
    0
    I had a similar problem with a USB buffer.
    The hardware buffer is not cached so can get out of step with RAM.
    I had to use "coherent" setting

    //must be uncached as dma'ed from usb hardware.
    uint8_t __attribute__((coherent)) transmitDataBuffer[64];
     
    #2
    azaman
    Starting Member
    • Total Posts : 43
    • Reward points : 0
    • Joined: 2018/06/14 05:08:52
    • Location: 0
    • Status: offline
    Re: DRV_SPI_BufferAddRead always returns 0xFF 2019/04/25 06:23:45 (permalink)
    0
    Hi nigel
     
    Thanks for the suggestion.
    I tried to declare  my rxbuffer as coherent but it did not help. I still get FF in my buffer
    #3
    azaman
    Starting Member
    • Total Posts : 43
    • Reward points : 0
    • Joined: 2018/06/14 05:08:52
    • Location: 0
    • Status: offline
    Re: DRV_SPI_BufferAddRead always returns 0xFF 2019/04/30 10:57:49 (permalink)
    0
     
    Turns out the SDI1 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 harmony  and also declaring the buffer as coherent was helpful atleast in our configuration.
    #4
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: DRV_SPI_BufferAddRead always returns 0xFF 2019/04/30 13:50:18 (permalink)
    4 (1)
    Is the connection to the SPI device on the same PCB, or ar you taking the signals "off board" ?
    For two devices to fail, it would seem likely you are getting static damage from external connections.
     

    Nearly there...
    #5
    azaman
    Starting Member
    • Total Posts : 43
    • Reward points : 0
    • Joined: 2018/06/14 05:08:52
    • Location: 0
    • Status: offline
    Re: DRV_SPI_BufferAddRead always returns 0xFF 2019/05/02 00:54:24 (permalink)
    0
    Yes the connection to spi is on the same PCB. The Pic32 is on the top whereas the spi flash is on the back side of the PCB and it is a 6 layer pcb. Do you think this could still be a problem? 
     
    Can you suggest how I can debug/ fix if this is going to be a problem?
    #6
    Jump to:
    © 2019 APG vNext Commercial Version 4.5