QSPI - Sending more than one packet

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

QSPI - Sending more than one packet

1,945 Views
WOLF
Contributor I
I'm using the M52233Demo board talking to an SPI Slave device. When I try to send 9 packets over SPI using the queue. the data that comes out of the Coldfire part is not what I expect. My code is below;
 
My Clock is good, my CS is help for the whole duration, but the data that comes out is skipping the 1st 3 btyes.
 
If i change my "do" loop to "for" loops I get the same issue.  If I remove the loops and use the code
 
change 1st loop to
MCF_QSPI_QDR   = MCF_QSPI_QDR_CONT |  MCF_QSPI_QDR_BITSE ;
MCF_QSPI_QDR   = MCF_QSPI_QDR_CONT |  MCF_QSPI_QDR_BITSE ;
MCF_QSPI_QDR   = MCF_QSPI_QDR_CONT |  MCF_QSPI_QDR_BITSE ;
 
change 2nd loop to
MCF_QSPI_QDR   = data[0];        
MCF_QSPI_QDR   = data[1];    
MCF_QSPI_QDR   = data[2];
 
It works fine.  ANy suggestions as to how i can do it in a loop? so i can use the saem function for different size transfers.
 
Code:
int spi_flash_program_array(long addr, char* data, int bytecount){ int i, ii; char addr1, addr2, addr3;  char SPI_Command;  if (SPI_FLASH_MODEL == AT25F)  SPI_Command   = AT25F_PROGRAM;               // Status Command else if (SPI_FLASH_MODEL == AT26DF)  SPI_Command   = AT26DF_PROGRAM;               // Status Command      addr1 = (addr & 0xFF0000)>>16;    addr2 = (addr & 0xFF00)>>8;    addr3 = addr & 0xFF;   MCF_QSPI_QMR   = (MCF_QSPI_QMR_MSTR | MCF_QSPI_QMR_BITS(8)  | MCF_QSPI_QMR_BAUD(2)); // Master, 16bits/transfer, 3.75Mhz MCF_QSPI_QDLYR = 0x0000;                // default delays MCF_QSPI_QIR = MCF_QSPI_QIR_SPIF;  MCF_QSPI_QAR   = MCF_QSPI_QAR_CMD; MCF_QSPI_QDR   = MCF_QSPI_QDR_CONT |  MCF_QSPI_QDR_BITSE ; MCF_QSPI_QDR   = MCF_QSPI_QDR_CONT |  MCF_QSPI_QDR_BITSE ; MCF_QSPI_QDR   = MCF_QSPI_QDR_CONT |  MCF_QSPI_QDR_BITSE ; MCF_QSPI_QDR   = MCF_QSPI_QDR_CONT |  MCF_QSPI_QDR_BITSE ;  i=0; do {  MCF_QSPI_QDR   = MCF_QSPI_QDR_CONT |  MCF_QSPI_QDR_BITSE ;   printf("setting up commadn Register...\n",i, i );  i++; } while (i<bytecount); printf("Writting at Address=%#x...\n", addr ); MCF_QSPI_QAR   = MCF_QSPI_QAR_TRANS;              // TX Address MCF_QSPI_QDR   = SPI_Command;               // Status Command MCF_QSPI_QDR   = addr1;                 // Status Command MCF_QSPI_QDR   = addr2;                 // Status Command MCF_QSPI_QDR   = addr3;                 // Status Command  i=0; do {  MCF_QSPI_QDR = data[i];   printf("Writting %#x at Address=%#x...\n",data[i], addr+i );  i++; } while (i<bytecount);    MCF_QSPI_QWR    = MCF_QSPI_QWR_CSIV | MCF_QSPI_QWR_NEWQP(0) | MCF_QSPI_QWR_ENDQP(3+bytecount); // Active Low CS, Transfer 1st slot of Queue   MCF_QSPI_QDLYR = MCF_QSPI_QDLYR_SPE;             // Start Transfer  while( !(MCF_QSPI_QIR & MCF_QSPI_QIR_SPIF )) {  // Spin here waiting for completion      }; printf("Write Complete\n");   return 0;}

 
Labels (1)
0 Kudos
2 Replies

299 Views
mjbcswitzerland
Specialist V
Wolf

Can this have something to do with compiler optimisiation removing some accsses in the loops? Check that MCF_QSPI_QDR is declared as volatile.

I have QSPI code which works when transmitting from loops - here's a snippet from an SPI FLASH driver:


Code:
        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 since we control it via port - 8 bit access        QAR = QSPI_TRANSMIT_RAM_0;                                       // set address to first transmit location        if (ucCommand != CONTINUOUS_ARRAY_READ) {                        // write type            QDR = *ucData++;                                             // prepare data            while (--DataLength != 0) {                                  // for each byte in the QSPI transfer block                QDR = *ucData++;                                         // prepare data                if (++iDataCnt >= 15) {                                  // maximum QSPI transfer length reached                    DataLength--;                    break;                }            }            QWR = ((0<<QSPI_START_SHIFT) | (iDataCnt<<QSPI_END_SHIFT));  // starting at queue 0 send/receive programmed entries            QDLYR = QSPI_SPE;                                            // start transfer - programmed number of bytes will be sent and read in        }

 

Regards

Mark

www.uTasker.com


0 Kudos

299 Views
WOLF
Contributor I
Thanks for your help,   Turned out it was the compilers optimization options.
 
I will try declaring MCF_QSPI_QDR as volatile later and see if i can turn on optimizations again.
 
 
 
 
0 Kudos