5 Replies Latest reply on Dec 16, 2018 2:37 AM by Klaus.Zobawa_3306126

    UART receiving problem

    marcogiorio

      Hi

      I'm trying to learn UART communication protocol, Actually I would  just write some command from the keyboard to my psoc 5lp device, I'm able to send character to set compare value of pwm or to send it back using Termite.

      The problems start when i want to send a number for example 100 (8 bit) to set PWM compare value instead of using ASCII code, it seems to not send it because I enabled an interrupt on received byte( blink a LED) and the interrupt doesnt fire.

      I'm using this API UART_ReadRxData(). I tried to read the datasheet without result

       

      I have several question:

      1)how to send something that is not an ASCII char?

      2)what happen if I send a number higher than 255? is it valid if i set 4byte buffer?

      3) Could explain when to create a Circular Buffer?

       

      Thanks to anyone will help me

        • 1. Re: UART receiving problem
          user_342122993

          marcogiorio,

          use example below as example of receiving command string with value from terminal into circular buffer

          UART string reception garbage value

          /odissey1

          1 of 1 people found this helpful
          • 2. Re: UART receiving problem
            user_1377889

            1)how to send something that is not an ASCII char?

            UART  is mainly made for transmitting ASCII and you can get one char after the other. Receiving binary data (0 to 0xff or 0 to 255) can work using UART_ReadRxData() but you need to check whether a byte was already received.

            2)what happen if I send a number higher than 255? is it valid if i set 4byte buffer?

            Only the lower 8 bits will be sent regardless of the buffer size.

             

            3) Could explain when to create a Circular Buffer?

            The component handles a circular buffer for you already. Just set the buffer size to > 4 (I use at least 80) and check for UART_GetRxBufferSize() > 0 to see if a byte is ready to read.

             

            Bob

            1 of 1 people found this helpful
            • 3. Re: UART receiving problem
              user_347933176

              Here are some code samples to show how I did it, sorry I cant post my complete project but this might help you :

              Param is my string buffer that contains the command parameters. You need to #include <stdio.h> and #include <string.h>

                      uint16 NrOfSamples=0;

                      if (0==sscanf(param,"%hu",&NrOfSamples)) return errWrongCmdParameters;

                      param=strtok(NULL," ;=");

               

              Or look at these examples for usage :

              C library function - sscanf()

              C library function - strtok()

              1 of 1 people found this helpful
              • 4. Re: UART receiving problem
                marcogiorio

                Thank you for the help guys.

                 

                Sorry for the mega post, I imagine they could be silly questions but I dont know where to find these informations, I know theory about RS232 protocol but to make it, it's really different .

                I hope not to bother you, if you could suggest me some material to improve my knowledge it could be great.

                 

                To Odissey1 and user_347933176: actually I am not be able to manage that kind of code I'm studying right now pointers in C, so this kind of code is quite hard for me, maybe in 1 or 2 weeks it could be an interesting exercise.

                 

                1)I followed Bob's advice about checking the if a byte was already received using if(UART_RX_STS_FIFO_NOTEMPTY==1)         and  it works fine but after this i used to send back data with UART_WriteTxData() checking on FIFO if empty and pn rxData,   but without good results...It doesnt works because it seems the second if condition is never true.

                 

                This was the easy code I used:

                 

                  if(UART_RX_STS_FIFO_NOTEMPTY==1)   

                  rxData = UART_ReadRxData();           

                  if( UART_TX_STS_FIFO_EMPTY!=0 && rxData!=0 )

                  UART_PutChar(rxData);

                 

                2)Luckly I found on the code examples something really easier that 'UART-full duplex example'.

                so I understood that is not enough to check only one bit in the RxDataRegister but I have to check also bit about error                  (Parity,stop,break..) but I cant understand the reason, If I want to send only the char C..why I have to check all these stuff,

                Why happen some errors if  I want send just one byte.

                 

                3) Using the code example i cant understand this:

                 

                rxStatus = UART_ReadRxStatus();

                if((rxStatus & (UART_RX_STS_BREAK      | UART_RX_STS_PAR_ERROR |

                UART_RX_STS_STOP_ERROR | UART_RX_STS_OVERRUN)) != 0u)

                 

                This is a bitwise operation isn't it?

                If yes , the output of UART_ReadRxStatus() is an uint8 and the other are all single bit how is possible to make any operation             between a single bit and a byte?

                • 5. Re: UART receiving problem
                  Klaus.Zobawa_3306126

                  FORTH for ....

                   

                  Hello marcogiorio,

                   

                  if you want to show an example of UART,

                  see: https://sourceforge.net/projects/mecrisp/files/Cypress/       >>> mecrisp-stellaris-2.4.5 for cy8c.........zip

                  Locking for 'cy-terminal.s', you will find some assemblercode.

                   

                   

                  Mecrisp-Stellaris-FORTH is available for following Eva-Kits / PSoC`s :

                  Board:          /          PSoC:

                  CY8CKIT-043     -> cy8c4247azi

                  CY8CKIT-044     -> cy8c4247azi

                  CY8CKIT-046     -> cy8c4248bzi

                  CY8CKIT-049     -> cy8c4245axi

                  CY8CKIT-050     -> cy8c5868axi

                  CY8CKIT-059     -> cy8c5888lti

                  FreeSoC2           -> cy8c5888axi

                   

                  The porting for the PSoC 6 is also planned. With this FORTH-pagage it is possible to test all C-applications interactively without debugger. The Kernel have integrated an interpreter and compiler. The Compiler is extendabel in FORTH itself (generic and generative programming).

                   

                  If you would like to know more about FORTH, you will find the classic Starting-FORTH and Thinking-FORTH by Leo Brodie:

                  https://1scyem2bunjw1ghzsf1cjwwn-wpengine.netdna-ssl.com/wp-content/uploads/2018/01/Starting-FORTH.pdf

                  http://thinking-forth.sourceforge.net/

                   

                  The Definition of ANS FORTH you can find here: http://lars.nocrew.org/dpans/dpans.htm

                   

                  If you want to know more about Mecrisp-Stellaris you are right here:

                  https://www.forth-ev.de/filemgmt_data/files/4d2015-arm.pdf

                   

                  Klaus