QSPI on MCF52235

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

QSPI on MCF52235

2,844 Views
FredT
Contributor II
    Hi, I'm trying to use the QSPI interface and I can't get the comm to work. I'm using only the clock, datain and dataout pins of the interface, and I'm driving myself the chip select pin. Can I do this ?

I'm writting command in the Command RAM of the interface like this:

MCF_QSPI_QAR = 0x20;
MCF_QSPI_QDR = 0xF000;

But when I'm trying to read theCommande RAM right after writting, this way:

MCF_QSPI_QAR = 0x20;
Data = MCF_QSPI_QDR;

Data is empty. Can I read the RAM ? In the Reference Manual, it's said to use the MCF_QSPI_QAR and MCF_QSPI_QDR register to read or write the QSPI RAM, so I suppose I can read or write all the QSPI RAM.

Thank you

Fred Talbot
Labels (1)
0 Kudos
6 Replies

777 Views
Arev
Contributor III
Hello,

For information, in the MCF5234/35 QSPI Module
 
QSPI Transmit RAM (0x00-0x0F) is WRITE ONLY,
QSPI Receive RAM (0x10-0x1F) is READ ONLY,
QSPI Command RAM (0x20-0x2F) is WRITE ONLY.
 
Your MCF52235 QSPI Module may works in the same way.
 
I Hope this helps..

Bye
 
<< Freescale MCF5234/35 with CodeWarrior 6.2 >>
0 Kudos

777 Views
FredT
Contributor II
Thank you, it explain part of my interrogation.

I'll keep searching for my bug. My pins are initiated, and the QSPI is initiated too.

Fred Talbot
0 Kudos

777 Views
mjbcswitzerland
Specialist V
Hi Fred

Here's the method for sending one byte and reading one byte of data (which is read in during the transmission of the first byte). The SPI module needs first to be initialised and the SPI lines configured for SPI use.
There is no problem to control the CS line as a GPIO - just don't configure it for SPI use (as below).

PQSPAR |= 0x0015;         // set QSPI_CLK, QSPI_DIN and QSPI_DOUT on QS port
QMR = ((QSPI_MSTR | QSPI_8BITS | QSPI_CPOL | QSPI_CPHA) | 2); // master mode with maximum speed

QAR = QSPI_COMMAND_RAM_0;                                            // set address to first control location
QDR = (QSPI_BITSE | QSPI_CS_3 | QSPI_CS_2 | QSPI_CS_1 | QSPI_CS_0);  // no chip select
QAR = QSPI_TRANSMIT_RAM_0;                                           // set address to first transmit location
QDR = 0x55;                                                                             // prepare test byte for transmission - 0x55
QWR = ((0<<QSPI_START_SHIFT) | (ucTxCount<<QSPI_END_SHIFT));   // starting at queue 0 send/receive entries where ucTxCount is the number of bytes to send/receive (1..16)
QDLYR = QSPI_SPE;                                                            // start transfer - bytes will be sent and read in

The test byte will now be transmitted and one byte read in. First you need to wait for a short time for the transmission to complete before reading otherwise the data will probabyl not yet be ready.

while (!(QIR & QSPI_SPIF)) {};                               // wait for transfer to complete
QIR = QSPI_SPIF;                                                  // clear interrupt flag (not used as interrupt but to monitor transmission/reception)


QAR = QSPI_RECEIVE_RAM_0;                          // set address to first receive location
ucRxByte = (unsigned char)QDR;                         // read and store what we have received

Regards

Mark

www.uTasker.com




0 Kudos

777 Views
FredT
Contributor II
Thank you, turned out it was the clock polarity (CPOL in QMR) that was the problem.

Now I able to read and write data in the eeprom.

Have a nice day !

Fred Talbot
0 Kudos

777 Views
FredT
Contributor II
Another problem: When I'm reading data, I'm waiting for the SPIF Flag to come up in the QIR Register, but when I'm reading the data right after, there's no data in the corresponding receive data register.

Here's the code:
        MCF_QSPI_QAR = MCF_QSPI_QAR_ADDR(MCF_QSPI_QAR_CMD);
        MCF_QSPI_QDR = QCR_cmd;
       
        // Data RAM a envoyer
        MCF_QSPI_QAR = MCF_QSPI_QAR_ADDR(MCF_QSPI_QAR_TRANS);
        MCF_QSPI_QDR = (i < DataOutCount) ? pDataOut[i] : 0;

        // SPI Execute command
        MCF_QSPI_QDLYR |= MCF_QSPI_QDLYR_SPE;
       
        // Waiting QSPI finished flag.
        while (!(MCF_QSPI_QIR & MCF_QSPI_QIR_SPIF)) {
        }

        // Reset Flags
        MCF_QSPI_QIR |= MCF_QSPI_QIR_SPIF & MCF_QSPI_QIR_WCEF;
       
        // Data RAM received
        MCF_QSPI_QAR = MCF_QSPI_QAR_ADDR(MCF_QSPI_QAR_RECV);
        Data = MCF_QSPI_QDR;

Any idea ?

Fred Talbot
0 Kudos

777 Views
blackjack
Contributor I

Hello Fredt,

                    I have the same problem as you have before in QSPI reading and writing method.

 

 

I cannot get the reading as i wrote the data in QSPI ram. I donot know what i have done wrong at the moment. Iam using the M52233 Demo board for the test.  I hope by now you have already solved the QSPI problem. Could you help me on this, thanks.

 

Here is the code below

 

void init_serial_flash( void )
{

MCF_QSPI_QDLYR = (MCF_QSPI_QDLYR_DTL(2) | MCF_QSPI_QDLYR_QCD(2)) ;   
      
    // QSPI interrupt disabled   
MCF_QSPI_QIR   = 0;

MCF_GPIO_DDRQS = 0; 

MCF_GPIO_PQSPAR |= 0x0015;

MCF_QSPI_QMR = (
     0
     | MCF_QSPI_QMR_MSTR
     | MCF_QSPI_QMR_BITS(8)
     /| MCF_QSPI_QMR_CPHA
     | MCF_QSPI_QMR_CPOL
     | MCF_QSPI_QMR_BAUD(2) 
      );

}

 

void write_to_qspi_ram( uint8 address, uint16 data )
{
 MCF_QSPI_QAR = address;
 MCF_QSPI_QDR = data;  
}


uint16 read_from_qspi_ram( uint8 address )
{
 MCF_QSPI_QAR = address;
 return( MCF_QSPI_QDR ); 
}

 

void Test_QSPI()
{
 
  write_to_qspi_ram(QSPI_COMMAND_RAM, (SPI_COM_BITSE | SPI_COM_CS3 | SPI_COM_CS2 | SPI_COM_CS1 | SPI_COM_CS0));
 write_to_qspi_ram(QSPI_TX_RAM, 0x55);
 MCF_QSPI_QIR = MCF_QSPI_QIR_SPIF;

 MCF_QSPI_QWR = MCF_QSPI_QWR_NEWQP(1);

 MCF_QSPI_QDLYR = MCF_QSPI_QDLYR_SPE;

 while( !(MCF_QSPI_QIR & MCF_QSPI_QIR_SPIF ))
 {
  // Spin here waiting for completion     
 }; 

  

 ReadData12[0] = read_from_qspi_ram(QSPI_RX_RAM);
 ReadData12[0] = read_from_qspi_ram(QSPI_RX_RAM+1);
 ReadData12[0] = read_from_qspi_ram(QSPI_RX_RAM+2);
 ReadData12[0] = read_from_qspi_ram(QSPI_RX_RAM+3);
 
}

0 Kudos