8 Replies Latest reply on Apr 7, 2019 11:32 PM by DheerajK_81

    UART String Processing

    trcac_4011561

      Platform: CY8CPROTO-062-4343W with Modus Toolbox 1.1 [on mac or PC (i've used both to program examples onto the kit)]

      Hello,

      I am attempting to use PSoC 6 and Modus Toolbox to interface with a sensor that communicates over UART. So far can successfully load "Hello World" and the "UART using low level API" examples, but this is as far as my understanding goes. I get confused about how to extend the function of the example to handle processing the strings. The sensor datasheet is attached to this post, and it outlines the communication protocol (8N1). My intention is to send an ascii string like #VERS\n from my Terminal or TeraTerm and get back the sensor's output. The datasheet says that all keywords are started with # and end with a new line character. When #VERS\n (or the other recognized strings are sent), the unit will echo the string and append values separated by spaces.

      I would like to learn the ins and outs, and am reading and watching cypress videos, but am getting overwhelmed and bogged down in manuals and not making useful progress. I feel like i'm in over my head, even though this seems like it's a fundamental concept and should be simple to implement. If someone is willing to provide some handholding guidance for a newbie that would be greatly greatly appreciated.

       

        • 1. Re: UART String Processing
          DheerajK_81

          Since your application code needs to frequently use standard IO library functions such as scanf and printf to perform input and output operations, we have provided the "Retarget IO" utility as part of the middleware.

           

          Please right click on <project_name>.mainapp, check the box that says, "Retarget IO" and click OK.

           

          You should observe two files being added under the Source directory as shown below:

          source_marked.png

           

          Open stdio_user.h and change the defines to point to the right SCB. Since UART is on SCB5, it will be modified to:

          uart_scb.PNG

           

          Now you can use the standard IO library functions (like printf and scanf) and process the strings based on your application accordingly and easily

           

          Regards,

          Dheeraj

          1 of 1 people found this helpful
          • 2. Re: UART String Processing
            trcac_4011561

            Hi Dheeraj! Thank you for the assistance. I'll read up on Retarget I/O and follow your instructions to get me started.

            • 3. Re: UART String Processing
              trcac_4011561

              Hi Dheeraj, if the sensor communicates over uart and I want to print to results to the console, how do I direct print and scan to both the Kitprog3 USB-UART and the sensor on another SCB cofigured as UART? Does retarget I/O allow me to choose which SCB receives/sends for multiple UARTS?

              • 4. Re: UART String Processing
                DheerajK_81

                You can specify whichever SCB you want for retarget I/O in the stdio_user.h like I mentioned previously. In your case, you can set the SCB used by the sensor for retarget I/O since it will need the print and scan the most. Once the data has been received, you can only use the UART APIs from the PDL (for eg: Cy_SCB_UART_PutString()) to print the results on the Kitprog3 USB-UART console since you can only have one SCB configured for retarget I/O.

                 

                Regards,

                Dheeraj

                2 of 2 people found this helpful
                • 5. Re: UART String Processing
                  trcac_4011561

                  Thanks! Okay, that makes things a bit more clear. I was under the impression I could dynamically change which SCB was addressed to Retarget I/O. So, I wrongly assumed there would be a way to "select" an SCB.. lets say SCB 5 for receiving data from the computer, then once that data was stored somewhere I could switch Retarget I/O to another SCB (say SCB 7) in order to use stio functions on more than one SCB in the same project. Now, with Retarget I/O configured for SCB 7 as UART, I'll learn how to get characters on SCB 5 from a terminal program, and pass them to SCB 7. Is there a ModusToolbox example of serial communication between the board and the computer that doesn't use Retarget I/O?

                   

                  Dheeraj, thank you you very much for your assistance, and patience with me. I understand this is very grassroots stuff, and that it can be tedious to deal with noobs. I very much appreciate the help while I'm just getting off my feet, and am looking forward to getting to a point of understanding the systems/code well enough to problem solve for myself. Hopefully I can write a functioning program now with your pointers.

                   

                  As a side question: Previously in your message that describes configuring Retarget I/O you instructed me to change the parameters to SCB 5. Can those parameters be made into a Variable? and can I write SCB 5 or SCB 7 into that variable as a way to retarget Retarget I/O during run time?

                  • 6. Re: UART String Processing
                    DheerajK_81

                    Yes, there is a code example. You can find it here

                     

                    Its my pleasure, every question that comes by definitely has some learning to offer, so thanks for asking, you should pat yourself for that.

                     

                    Coming to your question, I hadn't tried it yet so went ahead to try and implement this and got it to work. So, yes you can change the SCB during runtime by making modifications. I have attached the code along with comments. So I did some modifications in stdio_user.h by adding a variable which can be dynamically changed at runtime in main.c. Please have a look and let me know how it goes for you

                     

                    Regards,

                    Dheeraj

                    • 7. Re: UART String Processing
                      trcac_4011561

                      Hi Dheeraj,

                       

                      I was unsuccessful in getting the UARTs to switch, although I am certain this was on behalf of my misconfiguring something/placing code in the wrong place within ModusToolbox. I anticipate that in the next week or so I'll have an opportunity to retry. I attempted to start from the emptyPSoC6 project included with modus. So this time I think i'll start from the "Hello World" project that is on GitHub, or the included proto app that already has retarget I/O and SCB5 set up.

                       

                      Question: When configuring a UART, how do I know which Level to choose? High Level vs Low Level.. and if I should use low level, what's the process to set up interrupts? Where does initialization and configuration code go? (main.c always? always bove the for(;;)?)

                       

                      also, regarding the main.c and stdio_user.h files you graciously provided. are the lines with //comments the only ones you altered? do I need to change anything in the configurators?

                       

                      Kindly,

                      Travis C

                      • 8. Re: UART String Processing
                        DheerajK_81

                        Hello Travis,

                         

                        You can learn more about low level APIs here: Code-Examples-for-the-ModusToolbox-PSoC-6-SDK/CE219656_PSoC6_UARTLowLevelAPIs at mt1.1 · cypresssemiconductorco/Code-Exa…

                         

                        In the files I provided, those are the only changes. Nothing to do in the configurators except the enabling of UART on SCB5 and assigning TX and RX pins.

                         

                        Regards,

                        Dheeraj