1 2 3 Previous Next 40 Replies Latest reply on Jul 23, 2014 4:33 AM by dakn_263916 Go to original post
      • 15. Re: SPIM reading external memory incorrectly
        helic_263931

        Please open a new thread when you have a new problem. People won't always look at old threads, and you will get overlooked.

           

        To your problem: the master only creates a clock when it is sending data. If you want to read something after you have written the command, you need to send a dummy byte to the slave. It will get ignored by the slave, but the master reads the answer when doing this.

        • 16. Re: SPIM reading external memory incorrectly
          ki.leung

           We used PSOC3 with 25pe16 and no problem so far.

             

          I think it is better to upload your project for us to have a look. And also open a new thread as suggested.

          • 17. Re: SPIM reading external memory incorrectly
            userc_42609

            Thanks for your replies .Next time onowrds will open  thread for new problems.

               

            I uploaded the project here,please suggest what went wrong.

               

            Am sending dummy bytes to generate clock while reading, but getting 0x00  in MISO line.

               

             

               

            Thanks,

               

            Manju

            • 18. Re: SPIM reading external memory incorrectly
              ki.leung

              I'll have a look.

                 

              Have you tried to read the ID of the chip. This would be the first thing I do as the ID is a fix data stream.

              • 19. Re: SPIM reading external memory incorrectly
                userc_42609

                Yes,I tried to read Chip ID ,by sending command byte(0x9F) but getting zero's on miso line .

                   

                 

                   

                Thanks,

                   

                Manju

                • 20. Re: SPIM reading external memory incorrectly
                  ki.leung

                   If you cannot read ID, I would not try programming. 

                     

                  Can you show me how your read ID?

                     

                  Do you use the same routines as you posted?

                     

                  you can upload the readiD part for us to check.

                  • 21. Re: SPIM reading external memory incorrectly
                    ki.leung

                    "WE NEED A EDITING FEATURE"!!!!!

                       

                    I mean if you cannot read ID, I would not try to test the progrtamming(writing) the flash. Because there is not way of knowing whether the content is correct.

                    • 22. Re: SPIM reading external memory incorrectly
                      userc_42609

                       Hi ,In that project file, i commented the Read ID function.

                         

                      Below function to read the Chip ID of flash.Please let me know your thoughts on this.

                         

                       

                         

                      void ReadFlashRegisters()

                         

                      {

                         

                      uint32  i,counter,status ,timeout ;

                         

                      uint32 data_read = 0;

                         

                      uint8 rx_data = 0;

                         

                      i = counter = status = 0;

                         

                      timeout = 50000;

                         

                      DEBUG_UART_PutString("\r\nSend CMD");

                         

                      while ( 1 )  // For Testing Purpose Keep Sending CMD

                         

                      {

                         

                      DEBUG_UART_PutString("\r\nSend CMD");

                         

                      ChipSelect_Write(0x00);

                         

                      SPIMaster_WriteByte(0x9F);

                         

                      while ((SPIMaster_ReadTxStatus() & SPIMaster_STS_TX_FIFO_EMPTY) != SPIMaster_STS_TX_FIFO_EMPTY )

                         

                      {

                         

                      if ( counter++ > SPI_TIMEOUT_COUNTER )

                         

                      break ;

                         

                      }

                         

                      while ( timeout -- > 0 )

                         

                      {

                         

                      SPIMaster_WriteByte(0x33); //Dummy byte write 

                         

                      #if 1

                         

                      if((SPIMaster_GetRxBufferSize() > (uint8)0 ) && (SPIMaster_GetTxBufferSize() == (uint8)0))

                         

                      {

                         

                      while (SPIMaster_GetRxBufferSize() > 0)

                         

                      {

                         

                      rx_data = SPIMaster_ReadRxData(); ; 

                         

                      print_val(rx_data);

                         

                      DEBUG_UART_PutChar(',');

                         

                       

                         

                      }

                         

                      }

                         

                      #endif

                         

                      }

                         

                      timeout = 50000;

                         

                      ChipSelect_Write(0x01);

                         

                      i = 0;

                         

                      counter = 0;

                         

                      CyDelay(1000);

                         

                      }

                         

                      }

                         

                      Thanks,

                         

                      Manju

                      • 23. Re: SPIM reading external memory incorrectly
                        helic_263931

                        First - how did you configure the SPIM component? Is it 8bit, MSB first and the proper SPI mode (either 0/0 or 1/1)?

                           

                        Second - can you try to upgrade the SPI component? I see from the code that you use an older version (2.00 at most), and the curent one is 2.30.

                           

                        Third - when you send the first command (0x9f), you need to read one byte from the read buffer. For every byte written out by the master, another one is read, and this is true for the commands also.

                           

                        How large did you configure the RX buffer? If it is larger than 4 bytes (which is the recommended size) you get a software buffer, and GetRxBufferSize() returns 0 as long as only the hardware buffer is used.

                           

                        You while() loop is somewhat bogus: you put a byte in the write buffer - but this doesn't mean that it is written out when the function returns. Then you check that the transmit buffer is empty - which won't be the case. And then you proceed to write the next byte. This means that you never read anything. You need to add either a small delay after the write, or even better add a loop waiting for the transmit buffer to become empty.

                        • 24. Re: SPIM reading external memory incorrectly
                          userc_42609

                          SPI Configuration - Mode 0(CPHA 0 ,CPOL 0 ), 8Bit , MSB first . 

                             

                          RX buffer size is 8. I will try updating the components and inserting delay after writing the byte.

                             

                          Thanks for the suggestions .

                             

                           

                             

                          Thanks,

                             

                          Manju

                          • 25. Re: SPIM reading external memory incorrectly
                            ki.leung

                            The following is similar to what we use, Hope it helps.

                               

                            **********

                               

                             ulong ReadID(void)

                               

                            {

                               

                            ulong ulDataRead = 0;

                               

                            ChipDeselect();

                               

                            ChipSelect();

                               

                            /* read ID command */

                               

                            Write1Byte(RDID);

                               

                            SPI_ClearRxBuffer();

                               

                            ulDataRead = flashRead1Byte();

                               

                            ulDataRead <<= 8;

                               

                            ulDataRead |= flashRead1Byte();

                               

                            ulDataRead <<= 8;

                               

                            ulDataRead |= flashRead1Byte();

                               

                            ChipDeselect();

                               

                            return ulDataRead;

                               

                            }

                               

                             

                               

                            uchar Read1Byte(void)

                               

                            {

                               

                            SPI_ClearRxBuffer();

                               

                            Write1Byte(DUMMY);

                               

                            return SPI_ReadByte();

                               

                            }

                               

                            void Write1Byte(uchar ucData)

                               

                            {

                               

                            uchar ucStatus = 0;

                               

                            while (!(SPI_ReadStatus() & SPI_STS_TX_FIFO_EMPTY))

                               

                            {

                               

                            };

                               

                            SPI_WriteByte(ucData);

                               

                            while (!(SPI_ReadStatus() & SPI_STS_SPI_DONE))

                               

                            {

                               

                            };

                               

                            }

                               
                                ********   
                            • 26. Re: SPIM reading external memory incorrectly
                              ki.leung

                              A bit of error, 

                                 

                              here is the corrected one ...

                                 

                              ****

                                 

                               ulong ReadID(void)

                                 

                              {

                                 

                              ulong ulDataRead = 0;

                                 

                              ChipDeselect();

                                 

                              ChipSelect();

                                 

                              /* read ID command */

                                 

                              Write1Byte(RDID);

                                 

                              SPI_ClearRxBuffer();

                                 

                              ulDataRead = Read1Byte();

                                 

                              ulDataRead <<= 8;

                                 

                              ulDataRead |= Read1Byte();

                                 

                              ulDataRead <<= 8;

                                 

                              ulDataRead |= Read1Byte();

                                 

                              ChipDeselect();

                                 

                              return ulDataRead;

                                 

                              }

                                 

                               

                                 

                              uchar Read1Byte(void)

                                 

                              {

                                 

                              SPI_ClearRxBuffer();

                                 

                              Write1Byte(DUMMY);

                                 

                              return SPI_ReadByte();

                                 

                              }

                                 

                               

                                 

                              void Write1Byte(uchar ucData)

                                 

                              {

                                 

                              uchar ucStatus = 0;

                                 

                              while (!(SPI_ReadStatus() & SPI_STS_TX_FIFO_EMPTY))

                                 

                              {

                                 

                              };

                                 

                              SPI_WriteByte(ucData);

                                 

                              while (!(SPI_ReadStatus() & SPI_STS_SPI_DONE))

                                 

                              {

                                 

                              };

                                 

                              }

                                 
                                      
                              • 27. Re: SPIM reading external memory incorrectly
                                ki.leung

                                 The SPI mode is same as ours. 

                                   

                                we just set the rx and tx to 4 byte, but we read/write  one byte at a time and not really using the buffer.

                                • 28. Re: SPIM reading external memory incorrectly
                                  helic_263931

                                  Additional to the wait problema outlined above, a read buffer of 8 bytes implies the following:

                                     
                                        
                                  • an additional interrupt routine  is used to transfer bytes from FIFO to the software buffer
                                  •     
                                  • getRxBufferSize() returns 0 as long as received bytes are still in the FIFO, and are not read by the ISR
                                  •    
                                     

                                  Especially the latter one might get you. Since you try to read all bytes directly, use a buffer size of 4 (which uses the hardware FIFO only).

                                  • 29. Re: SPIM reading external memory incorrectly
                                    userc_42609

                                    I tried using above functions ,things didnt work for my badluck.

                                       

                                    I see the delay in between clock pulses because of function invokation and execution. That means clock is not continous.

                                       

                                    Is that causing the problem ?

                                       

                                    In data sheet features summary its saying 40Mhz to 50Mhz clock rate(maximum) .But if we set more then 24Mhz(based on Kbps rate setting) clock rate will get warning of clock accuracy.

                                       

                                     

                                       

                                    Thanks,

                                       

                                    Manju