14 Replies Latest reply on Feb 3, 2015 3:27 PM by DaKn_263916

    Uart psoc5

       Hi there,


      I would like to connect my dev psoc 5lp to the PC. Using Hyperterminal to input a number(interger) then do something on that number (convert to another number) the output it back to the PC. Is anyone here can help me with the template code? I've been looking into the uart datasheet but only template codes for TX,RX, and half size available.


      Thank you in advance,



        • 1. Re: Uart psoc5

          Easiest would be to use the USBUART component, no voltage-driver problems, no cable/wiring problems. Just use on PC-side the emulated COM-port. There are some example projects for USBUART, just right-click on the component on the schematic or in the catalog and select "Find Example Project".





          • 2. Re: Uart psoc5



            check previous post and UART project attached







            • 3. Re: Uart psoc5

               Thank you guys,


              I managed to get an example code that uses USBUART to control an LED's intensity. I will give it a try later to use the actual UART following Bob's example code.You guys are very helpful! 



              • 4. Re: Uart psoc5

                ...and you are always welcome!





                • 5. Re: Uart psoc5
                       Hi. Ive been trying to get the receive interrupt to work but have plenty of problems.   
                       I only seem to get a single character.    
                       When you say internal interrupt, does this internal interrupt run the supplied ISR:    
                       CY_ISR(UART_1_RXISR) ?? or is there something else?   



                  I notice in this isr that there are several statements such as :



                  UART_1_rxBuffer[UART_1_rxBufferWrite] = UART_1_RXDATA_REG;


                           increment_pointer = 1u;       
                         These are to transfer the data from the rx register into the Uart_1_rxBuffer[0,1..20]     


                       My problem is that I cant seem to get the data from the rxBuffer. only the first character.   
                       I have verified by signal analyzer that the frame is being sent and arriving at the rx pin. all is good there.:   
                       I use either a typical for loop   
                       mydata[I] = rxBuffer[I]   
                       or an assignment list but get the same results.   
                       Do I need to supply a long delay?   
                       What could be the problem??   
                  • 6. Re: Uart psoc5

                    Welcome in the forum, Joe.


                    Best practice is always to post your complete project here, so that we all can have a look at all of your settings. To do so, use
                    Creator->File->Create Workspace Bundle (minimal)
                    and attach the resulting file.


                    • 7. Re: Uart psoc5

                       hi Joe,


                      From the 1st impression, seems like you had couple of typos there where using "I" instead of "i" in your for loop. 


                      seconds...you just need to use the funciton "UART_IsReady()" to check whether the UART is ready to transfer the next data or not. 


                      But as Bob said, its better to post the whole project here then we can all help you out. 



                      • 8. Re: Uart psoc5



                        Thanks guys.


                        The loop code here isn't the real code. Just quickly typed.


                        Bob. I have to remove company code then Ill send tomorrow.


                        But still my question remains. What triggers the interrupt and is the ISR that is triggered the one in the UART int file?


                        By reading the datasheet it would seem that each arriving character triggers a separate interrupt. is this correct?


                        If so, I think what I am seeing is not the first but the last char sent. The loop is overwriting the first position every time and not advancing. So it would seem that the loop is the problem and what I need is a counter and a point to start it from.


                         BigD. I couldn't find any UART IS Ready() function.

                        • 9. Re: Uart psoc5

                          Hi. Here is attached project.


                          I simplified it a lot.


                          Mostly all is in the UART Interrupt file.


                          It polls a Modbus device for a register.


                          The device returns the message 04 03 02 00 00 74 44


                          The UART stores the data but when I try to retrieve it from the rxBuffer, First time it is polled, the info is correct. each additional time the information is incremented and placed in the wrong register of the DataIn registers.


                          How do I stop this incrementation??


                          Also there is a timer on the Top design.


                          Its purpose is to count serial bus pulses to determine if the bus is idle for a specific time.


                          It should enable when the bus goes high and interrupt after a specific time.


                          If the bus goes low it should reset the timer.


                          Is it configured ok?



                          • 10. Re: Uart psoc5

                            In the file UART_1_INT.c near line 180 you question the variable i outside of the loop. Per definition the value is not defined.


                            The stubs you use for UART are called everytime a character is received, so processing some characters at that point is not correct.




                            The interrupt for the PWM tc signal needs some modification:


                            Set the interrupt mode to "Rising Edge"


                            In the interrupt handler read the status of the PWM to clear the tc flag, look at the datasheet.


                            If you are expecting to receive a defined number of characters you may query UART_GetRxBufferSize() and act accordingly without using any interrupt.


                            Personally I do not like to make modifications in the generated files, they might get lost occationally. Have a look at the isr_StartEx() functions and the declarations using CY_ISR_PROTO() and CY_ISR() in the System Reference Guide which you find using Creator's "Help" menu.





                            • 11. Re: Uart psoc5

                              This might help -






                                        http://www.cypress.com/?rID=38267     AN54460












                              CY_ISR_PROTO(MyIntFunc);         // Prototype declaration




                              CY_ISR(MyIntFunc)                          // Interrupt function definition




                              // Place code here






                              In  initialization part of the program




                              isr_StartEX(MyIntFunc); // Start Interrupt with my handler




                              CY_ISR-macro have a look into the "System Reference Guide" under Help -> Documentation.




                              Regards, Dana.

                              • 12. Re: Uart psoc5

                                Hi. Thank you for the reply.


                                The problem seems to have been that the rx buffer needed to be cleared outside of the interrupt so I cleared it at the poll request. Works fine now.


                                But my questions about the timer and what exactly initiates the interrupt still need to be addressed.


                                I under stand and use the CYPROTO already.



                                • 13. Re: Uart psoc5

                                  "But my questions about the timer and what exactly initiates the interrupt still need to be addressed."


                                  Can you please precise your question?


                                  The timer itself does not generate an interrupt, instead the signal of the timer may be connected to an isr component.


                                  You connected an isr to the tc output. When changing the isr's mode to "rising edge" it should work correctly.





                                  • 14. Re: Uart psoc5

                                    "But my questions about the timer and what exactly initiates the interrupt still need to be addressed."




                                    The Tc output of timer triggers the external ISR, in your case named DeadSpaceTimer, per the following


                                    description of the Tc output in the datasheet -








                                    So when the timer completes a period it fires the interrupt for you letting you know


                                    it completed its timeout. Note you have timer configured in one shot mode, so you


                                    would need to restart the timer to generate another timeout.




                                    Regards, Dana.