This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

LPC2148 and FM25L512 memory, using SPI protocol

Hello

I have a device based on LPC2148 microcontroller with FM25L512 memory, connected to the SPI0 on microcontroller. I'm trying to use SPI example downloaded from nxp.com. Here is the code:

DWORD SPIInit( void )
{
    TxCounter = 0;

    S0SPCR = 0x00;
    PINSEL0 &= 0xFFFF00FF;
    PINSEL0 |= 0x00001500;
    IODIR0 = SPI0_SEL;
    IOSET0 = SPI0_SEL;

    S0SPCCR = 0x8;
    S0SPCR = SPI0_MSTR;
    return( TRUE );
}

BYTE SPIReceiveByte( void )
{
    BYTE data;

    S0SPDR = 0xFF;
    while ( !(S0SPSR & SPIF) );
    data = S0SPDR;
    return ( data );
}


The problem is that in SPIReveiceByte data variable is always set to 0xFF, whatever commands I send to the memory. Even when I change the dummy assignment ( S0SPDR = 0xFF;) to some else value - the result is 0xFF.

P.S. I have the same device with LPC2368 instead of 2148, and the same program based on the SPI examples from the nxp.com - it works.

May be somebody suggest something? Thank you

Parents
  • Of course. I do that.
    here is other parts of the code:

        IOCLR0 = SPI0_SEL;
        SPICmd[0] = WREN;
        SPISend( SPICmd, 1 );
        IOSET0 = SPI0_SEL;
    
        for ( i = 0; i < DELAY_COUNT; i++ );
    
        IOCLR0 = SPI0_SEL;
        SPICmd[0] = RDSR;
        SPISend( SPICmd, 1 );
        SPIReceive( SPIRDData, 1 );
        IOSET0 = SPI0_SEL;
    {skipped}
        for ( i = 3; i < BUFSIZE; i++ )
        {
            SPIWRData[i] = i;
        }
        IOCLR0 = SPI0_SEL;
        SPIWRData[0] = WRITE;
        SPIWRData[1] = 0x00;
        SPIWRData[2] = 0x00;
        SPISend( SPIWRData, BUFSIZE );
        IOSET0 = SPI0_SEL;
    {skipped}
        IOCLR0 = SPI0_SEL;
        SPICmd[0] = READ;
        SPICmd[1] = 0x00;
        SPICmd[2] = 0x00;
        SPISend( SPICmd, 3 );
        SPIReceive( SPIRDData, BUFSIZE - 2 );
        IOSET0 = SPI0_SEL;
    


    I've traced the progam using JTAG and S0SPDR is always 0xFF in SPIReceiveByte

Reply
  • Of course. I do that.
    here is other parts of the code:

        IOCLR0 = SPI0_SEL;
        SPICmd[0] = WREN;
        SPISend( SPICmd, 1 );
        IOSET0 = SPI0_SEL;
    
        for ( i = 0; i < DELAY_COUNT; i++ );
    
        IOCLR0 = SPI0_SEL;
        SPICmd[0] = RDSR;
        SPISend( SPICmd, 1 );
        SPIReceive( SPIRDData, 1 );
        IOSET0 = SPI0_SEL;
    {skipped}
        for ( i = 3; i < BUFSIZE; i++ )
        {
            SPIWRData[i] = i;
        }
        IOCLR0 = SPI0_SEL;
        SPIWRData[0] = WRITE;
        SPIWRData[1] = 0x00;
        SPIWRData[2] = 0x00;
        SPISend( SPIWRData, BUFSIZE );
        IOSET0 = SPI0_SEL;
    {skipped}
        IOCLR0 = SPI0_SEL;
        SPICmd[0] = READ;
        SPICmd[1] = 0x00;
        SPICmd[2] = 0x00;
        SPISend( SPICmd, 3 );
        SPIReceive( SPIRDData, BUFSIZE - 2 );
        IOSET0 = SPI0_SEL;
    


    I've traced the progam using JTAG and S0SPDR is always 0xFF in SPIReceiveByte

Children
No data