1 2 Previous Next 15 Replies Latest reply on Jul 13, 2017 7:31 AM by epr_1639216

    Connecting PSoC 4 and NRF24L01+ using SPI for a guitar wireless system project

    userc_41572

      Hello everyone, this is my first post on the forums. :)
      I am an EE student, and I'm currently trying to develop a guitar wireless system (like ie. www.alesis.com/guitarlink-wireless) as my bachelor of engineering thesis. I'm using PSoC 4 (CY8CKIT-049-42XX prototyping kit), NRF24L01+ transceivers (https://www.nordicsemi.com/kor/Products/2.4GHz-RF/nRF24L01P) and some other components. However, since I'm completely new to PSoC I am terribly lost in the process.

         

      I divided the whole project into smaller tasks, and the first thing I'm trying to achieve is simply the communication between two PSoC+NRF pairs. Due to the fact that I'm using the prototyping kit and the USB communication to program the chip, I placed the "bootloadable" component in the schematic design and provided it with .hex and .elf files I downloaded from the Internet. I also placed the SCB mode SPI Master component (I was unsure whether to use simply the SPI Master, or the SCB mode SPIM, but I guess the difference is software vs hardware, so I went with the 1st option), and I have a simple question to ask.

         

      If the hardware SCB component in PSoC is tied permanently to P4[0-3] pins, then why do I have the option to route it to other pins? Even worse - wy it IS routed to different pins in the SCB_SpiComm example? I expected the example project to clarify the issue, but it only made it worse.

         

      For better clarity of my problem I also provided the project files.

         

      More questions to come. Thanks in advance for any help. :)

        • 1. Re: Connecting PSoC 4 and NRF24L01+ using SPI for a guitar wireless system project
          JoMe_264151

          Welcome in the forum and in the fascinating world of PSoCs.

             

          There are two (2) SPI function blocks within a PSoC 4, thus the different pins. You should lock the pins after the first sucsessful compile, so that they do not change later. For many pin-components you are quite free to use any wanted pin, but on a PSoC4 there are some restrictions.

             

          An advice: If I were you I woud get me a Pioneer Kit-042. It has the advantage of beeing able to debug the code with breakpoints, single-step and inspecting variables and call-stack. Later you can use the very same (now tested") program for your Prototype Boards.

             

           

             

          Bob

          • 2. Re: Connecting PSoC 4 and NRF24L01+ using SPI for a guitar wireless system project
            joplc_301826

            Just got an nRF interface working with SCB SPI on that same kit for some testing.  Take a look here.  Just some hacked together stuff based on Deviation but should get you started.  Google knows about lots of nRF libraries for arduino and raspberry pi that shouldn't be hard to port if you want something more complete.

            • 3. Re: Connecting PSoC 4 and NRF24L01+ using SPI for a guitar wireless system project
              dakn_263916

              Dedicated pins and other topics -

                 

               

                 

                  

                 

                        

                 

              http://www.cypress.com/?rID=93401     AN86439 - PSoC® 4 - Using GPIO Pins

                 

               

                 

               

                 

              Regards, Dana.

              • 4. Re: Connecting PSoC 4 and NRF24L01+ using SPI for a guitar wireless system project
                userc_41572

                     @Bob

                   

                         

                   

                Yeah, I see now, I simply overlooked it earlier.
                Anyway, unfortunately the Pioneer Kit is more than 5 times more expensive than the Prototyping Kit. Even though it's an engineering thesis, my university doesn't finance such research, so if you also add the shipping cost, it just gets impossibly expensive for me to handle. So, I guess I will have to report some data to PC over USB_UART during the designing process

                   

                 

                   

                @hexfet

                   

                Nice, but the problem with already written libraries is... that they are already written. Sometimes it's just hard to understand code written by someone else. And if I have to port it to PSoC, I think I might as well write some of my own.

                   

                However, I also found a bachelor thesis on similar topic, with some nice looking code already written, but as I said - it's hard for me to understand it all. The thesis is available here.

                   

                @Dana
                Thanks, lots of useful information.

                   

                 

                   

                 

                   

                Anyway, I included some stuff in the schematic. It now has the Bootloadable component, SCB SPI component to communicate with the nRF module, IRQ and CE pins for the nRF module, and of course the SW and LED pins. Now I'd like to program the firmware, but at first I decided to try porting one of the libraries I found here. It's the same lib as used in the thesis mentioned above. It's clearly a library made for an other type of PSoC, so I have some questions.

                   

                 

                   

                We have these two functions:
                // Helper function for setting CSN off/on
                void nRF24_CSN_state( unsigned char state ){
                    if( state == CSN_ON){
                        PRT0DR |= nRF24_CSN_MASK;
                    }else{
                        //off
                        PRT0DR &= ~nRF24_CSN_MASK;
                    }
                }

                // Helper function for setting CE off/on
                void nRF24_CE_state( unsigned char state ){
                    if( state == CE_ON) {
                        PRT0DR |= nRF24_CE_MASK;
                    }else{
                        //off
                        PRT0DR &= ~nRF24_CE_MASK;
                    }
                }

                   

                Whilst having a CE pin component defined on schematic, can't I simply do some CE_Write? Also, the CSN pin is a part of the SPI component, I guess I have to use something like SPIM_SpiSetActiveSlaveSelect()?

                   



                Next function:

                   

                unsigned char nRF24L01_sendOneByte(unsigned char oneByte){

                    unsigned char status = 0x00;

                    // nRF24_CSN off
                    nRF24_CSN_state( CSN_OFF);

                    while( ! (SPIM_bReadStatus() & SPIM_SPIM_TX_BUFFER_EMPTY ) ); 
                        SPIM_SendTxData( oneByte );

                    while( SPIM_bReadStatus() & SPIM_SPIM_RX_BUFFER_FULL );
                        status = SPIM_bReadRxData();

                    // nRF24_CSN on
                    nRF24_CSN_state(CSN_ON);

                    Delay50uTimes(20);

                    return(status);
                }

                   

                It seems I can't find the equivalents for SPIM_bReadStatus(), SPIM_SPIM_TX_BUFFER_EMPTY and SPIM_SPIM_RX_BUFFER_FULL. Is _bReadStatus() the same as _SpiIsBusBusy()?
                 

                • 5. Re: Connecting PSoC 4 and NRF24L01+ using SPI for a guitar wireless system project
                  JoMe_264151

                  There are two different SPIM components for the PSoC4, one SCB (v2.0) and one UDB (v2.40) component. That's probably the difference you found.

                     

                  Yes, you may directly write to a pins-component with PinName_Write();

                     

                   

                     

                  Bob

                  • 6. Re: Connecting PSoC 4 and NRF24L01+ using SPI for a guitar wireless system project
                    userc_41572

                    Well, there's no _bReadStatus() in UDB SPI datasheet. It seems the command works for PSoC 1, vide this datasheet. However, there are separate _ReadRxStatus() and _ReadTxStatus() commands in PSoC 4 UDB Spi Master datasheet, but still, I'm using the SCB version, and it's API has even different commands.

                       

                     

                       

                    In conclusion, _bReadStatus() could be masked to test for specific conditions, like in:

                       

                    while( ! (SPIM_bReadStatus() & SPIM_SPIM_TX_BUFFER_EMPTY ) )

                       

                     

                       

                    So the whole second function goes kind of like this:

                       

                    send(byte){
                    status = 0;
                    chip_select_not = 0;
                    while tx_buffer is not empty
                    {send the byte of data}
                    while rx_buffer is full
                    {status = data read;}
                    chip_select_not = 1;
                    delay
                    return (status)}

                       

                     

                       

                    Should my version look like this?

                       

                    uint8 nRF24L01_sendOneByte(BYTE oneByte){

                        uint8 status = 0x00;

                        // nRF24_CSN off
                        nRF24_CSN_state( CSN_OFF);

                        while( ! (SCB_SpiUartGetTxBufferSize() == 0 ) ); 
                            SCB_SpiUartWriteTxData( oneByte );

                        while( SCB_SpiUartGetRxBufferSize() > 0 );
                            status = SCB_SpiUartReadRxData());

                        // nRF24_CSN on
                        nRF24_CSN_state(CSN_ON);

                        Delay50uTimes(20);

                        return(status);
                    }
                     

                       

                    PS. For some reason when I write "uint8" the IDE doesn't recognize what that means.. I guess it will be ok after I build the project?

                       


                     

                    • 7. Re: Connecting PSoC 4 and NRF24L01+ using SPI for a guitar wireless system project
                      userc_41572

                      Ok, so with help from the creator of a tutorial I mentioned earlier, I finally wrote some code, but unfortunately something's wrong.

                         

                      Here’s the code for the receiver: http://pastebin.com/ahHvsYh5 and for transmitter: http://pastebin.com/QLq57dC2

                         

                      Both units go through initialization, but when it comes to the main 'for' loop, the receiver goes on forever, but the transmitter goes through it only twice, and then stops. I only tried that with flashing an LED, I may try sending some data to the PC by UART, but for that I have to change pins etc.

                      • 8. Re: Connecting PSoC 4 and NRF24L01+ using SPI for a guitar wireless system project
                        JoMe_264151

                        If you want us to look into your projets you should consider to create a projet or workspace archive. This allows us to check component settings which somtimes hinder a normal execution. To do so, use
                        Creator->File->Create Workspace Bundle (minimal)
                        and attach the resulting file.



                        Bob
                         

                        • 10. Re: Connecting PSoC 4 and NRF24L01+ using SPI for a guitar wireless system project
                          JoMe_264151

                          Checked receiver project.

                             

                          You increase the index "dataSize" writing to the array "data", but you never reset the index which will overwrite into other vars and stack area.

                             

                           

                             

                          Bob

                          • 11. Re: Connecting PSoC 4 and NRF24L01+ using SPI for a guitar wireless system project
                            userc_41572

                            I reset it in the IF statement. (Shouldn't it be a WHILE loop by the way?) Then I go to the DO-WHILE loop (which runs the code 1-3 times, until RX_FIFO is empty (RX FIFO is 3 payloads max) thus incrementing dataSize), then I reset the interrupts and process the data accordingly to the value od dataSize (should have called it index or something). Then I get out of the IF statement, and main loop goes to the beginning, where I reset the dataSize variable. Or am I missing something?

                               

                             

                               

                            Also, the fact is that it never goes into the IF statement, meaning that it doesn't ever receive data.

                            • 12. Re: Connecting PSoC 4 and NRF24L01+ using SPI for a guitar wireless system project
                              userc_41572

                              Okay, I finally got to trying hexfet's library, and I can't even read a single register! It stops after clearing SPI RX buffer.

                                 

                              What am I missing?

                              • 13. Re: Connecting PSoC 4 and NRF24L01+ using SPI for a guitar wireless system project
                                userc_41578

                                Hi meffcio, did you ever get this working? I'm about to start the same project and wondered if you could share your code/experience further?

                                • 14. Re: Connecting PSoC 4 and NRF24L01+ using SPI for a guitar wireless system project
                                  shnc_1690291

                                  Hi

                                     

                                  This thread is looking incomplete, is any one checked this modified code ???  

                                     

                                  or is it working fine ???  Download NRF_Test_01.cyprj.Archive01.zip 

                                  1 2 Previous Next