1 2 3 Previous Next 30 Replies Latest reply on Feb 10, 2015 2:45 AM by JoMe_264151

    PSoC4: UART- Receiving String


      Hey All


      Wishing all of you and your families  a very happy and prosperous new year in advance !!!


      Anyone one working or has worked on UART? I need a task to be accomplished as below:


      - PSoC4 should receive a character string and store it in an array.


      - The programming should be interrupt based, specially with UART Rx interrupt and no delays included.


      For example, let us assume I am receiving a character string "OK\n". On receiving the entire string, I should come to know that the entire string has been received. I will compare that string with a setpoint string "OK\n". If both match, an LED should blink.







        • 1. Re: PSoC4: UART- Receiving String

          There is a UART Rx project in example projects, the Rx ISR is


          enabled in properties, however in the project itself the ISR is not


          "doing anything". Should be simple to add your code into that


          ISR (there are place holders for your code so it does not get over-


          written on compile, example below). Remember to declare global


          variables volatile that are used in your ISR.




                  /* User code required at start of ISR */
                  /* `#START UART_1_RXISR_START` */

                  /* `#END` */




          Regards, Dana.

          • 2. Re: PSoC4: UART- Receiving String

            The last character of the string is "\n" which is 0x0a in ASCII. When you buffer your string (could be a circular buffer) you can signal the controlling program that a complete string has arrived.


            -Mark begin of string


            -Get character.


            -When character is \n store 0x00 (end-of-string indicator) and signal "String received" else store character and loop







            • 3. Re: PSoC4: UART- Receiving String

              Attached is example  project of using UART for receiving commands. It utilizes non-blocking circular buffer to receive characters from UART Rx and split them into command messages when termination characters are found (0x0D and/or 0x0A). Project closely follows code posted by Bob Marlowe before. This demo shows how to change colors of the LED on the PSoC4 PioneerBoard.


              Each received message has one "command" byte followed by "value string":


              <cmd><value string> <\r> [<\n>], example: R255\n (set red LED to 255).


               If one <cmd> byte is not enough for your commands, change it to 2 (or more).


              Note that in this project UART rate was set to 230k to match speed  of my Bluetooth HC-05 dongle. Change it to your own UART rate.



              • 4. Re: PSoC4: UART- Receiving String

                Thank you everyone for giving solutions, though I am still not getting results. Please share a project that works with UART Receive interrupt configured such as an interrupt is generated each time a byte is received.


                Thanks in advance.







                • 5. Re: PSoC4: UART- Receiving String

                  The project Odissey1's posted contains some usable code, why don't you base on that or do you have got any other difficulties?





                  • 6. Re: PSoC4: UART- Receiving String



                    in my project, interrupt is fired on every char received, but then characters go into receiving buffer for further processing when CPU is available. This way UART will not interrupt processes run by the CPU. This is the way simple UART input should operate...




                    If you don't need complex command structure, just replace processing portion in the above project with:




                    void ProcessCommandMsg(void)






                         //check received message for valid command




                         if (RB.RxStr == 'OK') // 'OK' string received..     




                              \\do something...







                    • 7. Re: PSoC4: UART- Receiving String

                      Thank you all for support. I am sorry I replied late as I was having some other tasks on plate. Check my next post on this thread only, that discusses the GSM SIM300 related project.







                      • 8. Re: PSoC4: UART- Receiving String

                        Bob, Dana and Odissy


                        Thanks for your support. Actually I am working on GSM SIM300 module interfacing with PSoC4 and developing project for sending and receiving messages on certain events. In this project, I need to take care of the timeout feature also. If any of all of us has worked on GSM SIM300, he/she can help me out with this. For those who have not worked on it, I have a SIM300 library for AVR microcontroller that I found while searching on internet. I believe we all can do the analogy of PSoC4 with AVR and have a complete GSM solution, which is never done as far as I know. Please find attached the entire project targetted to AVR based on C language. The developer of the project is Mr. Avinash Gupta. Here is the link that explains the project:




                        Please go through this project and let this thread be live through open discussion and development for GSM SIM300 with PSoC4.







                        • 9. Re: PSoC4: UART- Receiving String

                          Can anyone please explain how to write UART receive interrupt service routine and clear the UART Rx FIFO not empty interrupt? Currently I am sending "AT" command to the GSM SIM300 Module and want to receive "OK" in return. But I am not getting desired results. When I debugged it, I came to know that my code does not come out of UART Interrupt service routine. Please find attached my project.

                          • 10. Re: PSoC4: UART- Receiving String

                            Hi Shaunak!


                            Just use


                                ch = UART_UartGetByte();


                            Dangerous is the use of a global variable named ch which can be overlooked/overwritten easily. Additionally it should be declared to be volatile since it is changed in an interrupt handler.


                            You write data to the LCD. This should not be done in an interrupt handler because you may run into troules later when the project grows: Writing to LCD contains some delays which will hinder any other interrupt to be handled until this interrupt finishes. That could be a remarkable time making other parts of the progem to fail.


                            Usually the structure of an interrupt-driven receiver just reads-off the character and saves it in a buffer, clearing the interrupt and optionally setting a flag indicating a char received or found an end-of-message,. In the main-loop the flags are checked and acted upon them. 





                            • 11. Re: PSoC4: UART- Receiving String

                              Hi Bob!


                              Thank you. It works now as per your suggestions.





                              • 12. Re: PSoC4: UART- Receiving String

                                Shaunak, you are always welcome!





                                • 13. Re: PSoC4: UART- Receiving String

                                  Hi people.
                                  In first time sorry to write this question in this post. I am newly
                                  1º) how do i open new thread?


                                  2º) my question is: I try to communicate (In basic form) the UART block with the Hyperterminal. if I put  UART_1_UartPutString("Ejemplo") I recive (in Hyperterminal) ASCII noise. No the word Ejemplo


                                  then how i solve this?


                                  very thanks for your patience and time

                                  • 14. Re: PSoC4: UART- Receiving String

                                    Welcome in the forum!


                                    Check the baud-rate selected for HyperTerminal and your UART, must be the same.





                                    1 2 3 Previous Next