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

MCB2300 + SPI serial flash issue

Hello,

I'm trying to use the MCB2300 board (LPC2378) with an external serial flash using SPI (ST M25P80).
First, I used SPI without interrupt and it works without any problem. But LPC2378 SPI has a maximum clock of 9MHz (with a 72MHz master clock). And I would like to use my flash with a faster clock.

So I tried to use the SSP. I didn't manage to use it without interrupt (I never read something although my write signal seems to be good on the scope). Then I tried to use SSP with interrupt. Sometimes I can read and erase some bytes and sometimes not.

Moreover, I tested to use the automatic "SSEL" chip select, set by LPC2378. But it seems to deselect between 2 frames and it's not compatible with my serial flash according to the datasheet. So I tried a manual chip select, with a GPIO, between each instruction. Without any success.

Here is my sequence :

Start
InitSPIMaster(); // initialize the driver
B = SPI_ReadStatus();
SPI_ReadData(0,P1,2); // Read data (2 bytes in P1 array) from address 0
SPI_EraseChip();
SPI_ReadData(0,P1,2); // Read data
SPI_WriteEnable(1); // Enable Writes
SPI_WriteData(0,P0,2); // Write data (2 bytes from P0 array) in address 0
SPI_ReadData(0,P1,2); // Read data
End

Is there something wrong ?

According to me, the SPI initialisation is good, since the 'read status' and 'write' function looks good.

I had to this that I started my work with the 'lpc_ssp.c' and 'lpc_ssp.h' library from C. Strahm (found on web).

Could someone help me please ?

Thank you so much in advance.

Aurelien

  • You are not showing where you are setting your SSEL-signal in relation to your reads and writes. Is it in SPI_ReadData() and SPI_WriteData()?

    I have been using the SSP and I had to drive the SSEL signal as GPIO since the automatic drive did not correspond with my needs.

    Are you waiting until the SSP device is idle before deselecting SSEL? Note that the SSP has a FIFO so you can write multiple bytes to it that it will then continue to send as fast as it can.

    But with this as with most other problems relating communication: Have you looked at the signaling with an oscilloscope? Based on the oscilloscope view:
    - what did you expect to happen?
    - what did happen?
    - what was the exact code involved?

  • Thank you so much for replying quickly !

    First of all, I use an ascilloscope to check every signal. I tested a lot of cases :
    - with automatic drive by SSEL or with manual drive with a GPIO.
    - with a polling of the slave's status register prior to send each command/ with the same polling but after each command / with no polling.

    The interesting information is :
    - with auto drived SSEL , I managed to read the status register or send short commands like 'erase'. But when I send long commands (more than 5 bytes), the SSEL sometimes deselect between 2 bytes. I think this is why the behaviour wasn't stable.

    Yesterday I start again with a new, easier and clearer code. I used a GPIO to drive manually the chip select. I finally succeed in writing, reading and erasing some bytes. Now I need to improve my code to allow it to support bigger data and with an higher speed.

    But it remains a question concerning the auto drived SSEL. According to the lpcxx user manual, 'For continuous back-to-back transmissions, the SSEL pins remains in its active LOW
    state, until the final bit of the last word has been captured, and then returns to its idle state'. I can't find how and why this signal is switching alhough it shouldn't.

    Thank you again for helping me and hope my work will help somebone else !

  • Dear Aurelien
    Sorry,here I am not giving you solution on ur problems.
    but u can help me on my SPI communication LPC2378 with dataflash (AT456DB161)</>b.Here I am in trouble from few days.I am not getting data on S0SPDR after simulation.
    Here is my SPI master initalization

    void InitSPI(void)
    {
    
                    PCONP   |= 0x100;
                    PINSEL0  |= 0xC0000000;                 //P0.15    spi pin configuration
                    PINSEL1 |= 0x0000003F;          //P0.16,P0.17,P0.18
    
                    PCLKSEL0 |= 0x00000000;                 //PCLK= CCLK/4
    
    
    
                    IODIR0          = SPI0_SEL;
                    IOSET0  |= 0x4000;
                    IODIR0          = 0x4000;
                    IOSET0  |= 0x800;
    
                    S0SPCCR  |= 0xA5;
                    //S0SPCCR        |= 0xA8;                          // spi bus frequency
    
    
                    S0SPCR  |= 0x20;                                //CPH = 0, CPOL = 0
    
    
    

    Here I am writing on SPI (S0SPDR register)

    void WrToflash(unsigned int BaseAdd,unsigned char size,unsigned char *buffAdd1)
    {
            unsigned char k;
            unsigned char u32dummyData;
            for (k=0;k<size; k++)
            {
                    IOCLR0           |= 0x4000;
    
    
    
                    S0SPDR   = 0x87;
                    while (!(S0SPSR & SPIF));
                    u32dummyData    = S0SPDR;
    
                    S0SPDR = (BaseAdd>>8) & 0xFF;
                    while (!(S0SPSR & SPIF));
                    u32dummyData = S0SPDR;
    
                    Delay(1000);
                    S0SPDR = BaseAdd & 0xFF;
                    while (!(S0SPSR & SPIF));
                    u32dummyData = S0SPDR;
    
                    BaseAdd++;
    
                    S0SPDR = buffAdd1[k];
                    while (!(S0SPSR & SPIF));
                    u32dummyData = S0SPDR;
    
                    IOSET0 |= 0x4000;
            }
    }
    
    

    Here I am reading from SPI (S0SPDR register)

    
    void RdFromflash(unsigned int BaseAdd2,unsigned char size2,unsigned char *buffAdd2)
    {
            unsigned char j;
            unsigned char u32dummyData2;
    
            IOCLR0 |= 0x4000;
    
            S0SPDR = 0xD6;                  //opcode for rading flash location
            while (!(S0SPSR & SPIF));
            u32dummyData2 = S0SPDR;
    
            S0SPDR = (BaseAdd2>>8) & 0xFF;
            while (!(S0SPSR & SPIF));
            u32dummyData2 = S0SPDR;
    
            S0SPDR = BaseAdd2 & 0xFF;
            while (!(S0SPSR & SPIF));
            u32dummyData2 = S0SPDR;
    
    
            for (j=0;j<size2;j++)
            {
                    Delay(1000);
                    S0SPDR = 0;                     //Dummy write
                    while (!(S0SPSR & SPIF));
                    buffAdd2[j] = S0SPDR;
            }
            IOSET0 |= 0x4000;
    
    }
    

    Here what happen I observed status on simulator.
    all SPI register i observed all all modify according to my settings except datar egister(S0SPDR), when I observed S0SPDR during writing data,i am writing 0x87 but it is not modify,it only showing 0x00.at that time my SPI transfer flag bit is set.
    so Is my (desired)data transfer is completed,if completed what value it is transfer?

    At the time of reading I am getting 0xFF on my hyperterminal.so what will be exect issue?

    Plz help me regarding this issue.and you can.because you are allready done these things.
    you can send your code on my mail ID
    shyam_tayade@rediffmail.com

    wating for your positive reply.....

    regards
    Shyam T.
    Pune India

  • Thanks a lot sir

    regards
    Shyam T.
    Pune India.

  • Dear Aurelen

    I not getting your mail.
    will u send me again?
    My mail ID is
    shyam_tayade@rediffmail.com
    or u can send me
    ganeshbadgujar99@yahoo.co.in

    regards
    Shyam T.
    pune India

  • Got your coad
    Thank a lot.

    Regards

    Shyam.T
    Pune India

  • Got your coad
    Thank a lot.

    confusing the perpetrator and the victim?

  • Dear Aurelien
    Thank you very much. for your valuable help
    my SPI communication is working.from your code i got lot of help.
    be in touch.....

    regards
    Shyam T.
    Pune India.

  • Would you mind sharing your advice?

    I would like to know the correct way of handling S0SPSR and S0SPDR.

    Thanks, Garfay.