AnsweredAssumed Answered

SPI RXFIFO - Debugging

Question asked by miller.mike.003 on Apr 1, 2014
Latest reply on Apr 1, 2014 by gonzalez.laurent
All,

Thank you for taking the time to read this and sending over any ideas that you have.

1.) I am sending out SPI commands to some external serial flash.

2.) I am sending out a command 0x9F followed by 3 dummy bytes (0xAA) to clock out the device information. (manufacturer ID (1 byte), memory type (1byte), and density (1 byte)).

3.) I am expecting to see 0xC2, 0x20, 0x16 clocked out from the device.

4.) When I check the oscilloscope waveforms I can see the data 0xC2, 0x20, 0x16 in the data coming in the correct order.

5.) I read the data register many times after my my last transmit to pull data out of the receive fifo.  Between the array I am placing data in from reading the data register and the final look at the data register before I exit my function I can see the data scrambled around in there but not in the order I am expecting. I was expecting to see 0xC2 0x20 0x16 as a sequence in the receive array. But this is not what i see.

6.) You can see after my last dummy byte I start reading data in from the receive FIFO.

7.) If I put a while(1); after my last dummy byte sent out I don't see the FRLVL (FIFO reception level) change at all.  The value of FRLVL in the debugger is 0x00 indicating that the FIFO is empty.  I was expecting this register to be "0x03" with 3 bytes ready to be read in.  I do see the data sitting in the two "DR" registers in the debugger. I attached an attachment to show this.

8.) Code:

void read_id(void)
{

      unsigned char received1[15];
      
        //  Initialize array to some defined state.
        received1[0] = 0xAF;
        received1[1] = 0xAF;
        received1[2] = 0xAF;
        received1[3] = 0xAF;
        received1[4] = 0xAF;
        received1[5] = 0xAF;
        received1[6] = 0xAF;
        received1[7] = 0xAF;
        received1[8] = 0xAF;
        received1[9] = 0xAF;
        received1[10] = 0xAF;
        received1[11] = 0xAF;
        received1[12] = 0xAF;
        received1[13] = 0xAF;
        received1[14] = 0xAF;
        
             
        // Here is where I need to check to be sure that the read-> is empty.
        received1[0] = SPI1->DR;                   // Reading back 0x02
        received1[1] = SPI1->DR;                   // Reading back 0x02
        received1[2] = SPI1->DR;                   // Reading back 0x02
        received1[3] = SPI1->DR;                   // Reading back 0x02
        received1[4] = SPI1->DR;                   // Reading back 0x02
        received1[5] = SPI1->DR;                   // Reading back 0x02
        received1[6] = SPI1->DR;                   // Reading back 0x02
        received1[7] = SPI1->DR;                   // Reading back 0x02
        received1[8] = SPI1->DR;                   // Reading back 0x02
        received1[9] = SPI1->DR;                   // Reading back 0x02
        received1[10] = SPI1->DR;                   // Reading back 0x02
        received1[11] = SPI1->DR;                   // Reading back 0x02
        received1[12] = SPI1->DR;                   // Reading back 0x02
        received1[13] = SPI1->DR;                   // Reading back 0x02
        received1[14] = SPI1->DR;                   // Reading back 0x02
        
        
        // Here is where I need to check to be sure that the read-> is empty.
        received1[0] = SPI1->DR;                   // Reading back - no change
        received1[1] = SPI1->DR;                   // Reading back no change
        received1[2] = SPI1->DR;                   // Reading back no change
        received1[3] = SPI1->DR;                   // Reading back no change
        received1[4] = SPI1->DR;                   // Reading back no change
        received1[5] = SPI1->DR;                   // Reading back no change
        received1[6] = SPI1->DR;                   // Reading back no change
        received1[7] = SPI1->DR;                   // Reading back no change
        received1[8] = SPI1->DR;                   // Reading back no change
        received1[9] = SPI1->DR;                   // Reading back no change
        received1[10] = SPI1->DR;                   // Reading back no change
        received1[11] = SPI1->DR;                   // Reading back no change
        received1[12] = SPI1->DR;                   // Reading back no change
        received1[13] = SPI1->DR;                   // Reading back no change
        received1[14] = SPI1->DR;                   // Reading back no change
        
         
       // Write out the read id command.
        SPI_Cmd(SPI1, ENABLE);
        
        SPI_SendData8(SPI1, 0x9F);
        // Wait until transmit buffer is empty than continue
        while(  !(SPI1->SR & 0x02)  );
       
      
        ///////////////////////////////////////////////////////////////////////
        // DUMMY BYTE 1
        SPI_SendData8(SPI1, 0XAA);
        // Wait until transmit buffer is empty than continue
        while(  !(SPI1->SR & 0x02)  );      
        
        
        ///////////////////////////////////////////////////////////////////////
        // DUMMY BYTE 2
        SPI_SendData8(SPI1, 0xAA);
        // Wait until transmit buffer is empty than continue
        while(  !(SPI1->SR & 0x02)  );      
        
        
        ///////////////////////////////////////////////////////////////////////
        // DUMMY BYTE 3
        SPI_SendData8(SPI1, 0xAA);
        // Wait until transmit buffer is empty than continue
        while(  !(SPI1->SR & 0x02)  );      
        
           
        // Reading what is in the RXFIFO - looking for 0xC2 0x20 0x16
        received1[0] = SPI1->DR;                   // Reading back 0x02 ; if breakpoint here then 0x16
        received1[1] = SPI1->DR;                   // Reading back 0xC2;  0x16 if breakpoint at [0];
        received1[2] = SPI1->DR;                   // Reading back 0X02 ;  0x16 if breakpoint at [0];
        received1[3] = SPI1->DR;                   // Reading back 0x02;  0x16 if breakpoint at [0];
        received1[4] = SPI1->DR;                   // Reading back 0x16;  0x16 if breakpoint at [0];
        received1[5] = SPI1->DR;                   // Reading back 0xC2;  0x16 if breakpoint at [0];
        received1[6] = SPI1->DR;                   // Reading back 0xC2;  0x16 if breakpoint at [0];
        received1[7] = SPI1->DR;                   // Reading back 0xC2;  0x16 if breakpoint at [0];
        received1[8] = SPI1->DR;                   // Reading back 0xC2;  0x16 if breakpoint at [0];
        received1[9] = SPI1->DR;                   // Reading back 0xC2;  0x16 if breakpoint at [0];
        received1[10] = SPI1->DR;                   // Reading back 0xC2;  0x16 if breakpoint at [0];
        received1[11] = SPI1->DR;                   // Reading back 0xC2;  0x16 if breakpoint at [0];
        received1[12] = SPI1->DR;                   // Reading back 0xC2;  0x16 if breakpoint at [0];
        received1[13] = SPI1->DR;                   // Reading back 0xC2;  0x16 if breakpoint at [0];
        received1[14] = SPI1->DR;                   // Reading back 0xC2;  0x16 if breakpoint at [0];
        
        
        SPI_Cmd(SPI1, DISABLE);                   // De-assert the chip select line
            
        
}

Thanks.

-Mike

Attachments

Outcomes