MCF52223 - Serial Peripheral Interface Setup

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MCF52223 - Serial Peripheral Interface Setup

1,604 Views
PopsStack
Contributor I
Hi
 
Can anyone assist in the setup and use of the SPI on the 52223
 
Thanks
 
Pops
Labels (1)
0 Kudos
2 Replies

385 Views
RichTestardi
Senior Contributor II
If it helps, I use the qspi on the M52221DEMO board to program the EzPort of my other boards.
 
The full code for that project is here:
 
 
Or if you're just interested in the qspi read/write routine, it is below, and the initialization code below that.
 
Code:
// perform both output and input qspi i/ointflash_qspi(byte *buffer, int length){    int i;    int request;    while (length) {        request = MIN(length, 16);        for (i = 0; i < request; i++) {            // set up the command            MCF_QSPI_QAR = MCF_QSPI_QAR_CMD+i;            MCF_QSPI_QDR = MCF_QSPI_QDR_CONT;            // copy tx data to qspi ram            MCF_QSPI_QAR = MCF_QSPI_QAR_TRANS+i;            MCF_QSPI_QDR = buffer[i];        }        // set the queue pointers        assert(request);        MCF_QSPI_QWR = MCF_QSPI_QWR_ENDQP(request-1)|MCF_QSPI_QWR_NEWQP(0);        // start the transfer        MCF_QSPI_QDLYR = MCF_QSPI_QDLYR_SPE;        // wait for transfer complete        assert(! (MCF_QSPI_QIR & MCF_QSPI_QIR_SPIF));        while (! (MCF_QSPI_QIR & MCF_QSPI_QIR_SPIF)) {        }        MCF_QSPI_QIR = MCF_QSPI_QIR_SPIF;        assert((MCF_QSPI_QWR & 0xf0) >> 4 == request-1);        assert(! (MCF_QSPI_QDLYR & MCF_QSPI_QDLYR_SPE));        for (i = 0; i < request; i++) {            // copy rx data from qspi ram            MCF_QSPI_QAR = MCF_QSPI_QAR_RECV+i;            buffer[i] = MCF_QSPI_QDR;        }        buffer += request;        length -= request;    }    MCF_QSPI_QWR = MCF_QSPI_QWR_CSIV;}

 
Initialization:
 
Code:
    // QS is primary    MCF_GPIO_PQSPAR = 0x1555;    // initialize qspi master at 100k baud    assert(MASTER_FSYS/2/100000 < 256);    MCF_QSPI_QMR = MCF_QSPI_QMR_MSTR|/*MCF_QSPI_QMR_CPOL|MCF_QSPI_QMR_CPHA|*/MASTER_FSYS/2/100000;    MCF_QSPI_QWR = MCF_QSPI_QWR_CSIV;

 
0 Kudos

385 Views
michele_darold
Contributor I
For serial flash I use the code taht you can find in freescale example of LiteHttpServer or some else
I have connected a spansion serial flash to qspi bus and I use this code to do the initialisation.
If you search for example of LiteHttpserver you can find the complete code for a driver with a serial flash
void init_serial_flash( void )
{
    // No delay, disable QSPI
    QDLYR = 0;
    
    // QSPI interrupt disabled
    QIR   = 0;
    

    // QMR[BAUD] = fsys/ / (2 × [desired QSPI_CLK baud rate])
    // QMR[BAUD] = 60000000/(2*8000000)
    // Using 3 will yield a baud rate of 10Mhz
    QMR = (0|    
                    QMR_MSTR_BITMASK|
                    QMR_BITS(8)|
                    QMR_BAUD(3)    
                   );

    // Pin assignments for port QS
    //     Pin QS6 : GPIO input
    //     Pin QS5 : GPIO input
    //     Pin QS4 : GPIO input
    //     Pin QS3 : QSPI chip select QSPI_CS0
    //     Pin QS2 : QSPI serial clock, QSPI_CLK
    //     Pin QS1 : QSPI serial data input, QSPI_DIN
    //     Pin QS0 : QSPI serial data output, QSPI_DOUT

    //     DDRQS[DDRQS6]   = 0
    //     DDRQS[DDRQS5]   = 0
    //     DDRQS[DDRQS4]   = 0
    //     DDRQS[DDRQS3]   = 0
    //     DDRQS[DDRQS2]   = 0
    //     DDRQS[DDRQS1]   = 0
    //     DDRQS[DDRQS0]   = 0
    DDRQS &= 0xF0;

    //     PQSPAR[PQSPAR6] = 0
    //     PQSPAR[PQSPAR5] = 0
    //     PQSPAR[PQSPAR4] = 0
    //     PQSPAR[PQSPAR3] = %01
    //     PQSPAR[PQSPAR2] = %01
    //     PQSPAR[PQSPAR1] = %01
    //     PQSPAR[PQSPAR0] = %01
    PQSPAR = PQSPAR_PQSPAR3(0x1) |
             PQSPAR_PQSPAR2(0x1) |
             PQSPAR_PQSPAR1(0x1) |
             PQSPAR_PQSPAR0(0x1);
                       
}

0 Kudos