6 Replies Latest reply on Feb 16, 2016 3:34 AM by user_1377889

    interrupt on Uart

    cathal.ferrydl_1479341

      Hi,

         

      I was wondering how to use the interrupt correctly on the psoc 3,

         

      ive been trying out the sample code on psoc creator, i see on the UART block that i can enable an interrupt on received byte rather than the program polling and holding up the program while its waiting for data to arrive. Is this handled automatically in the background by PSoC creator when i select interrupt on rx byte?

         

      also i noticed that there is a buffer size associated with the rx interrupt, it seems to be four bytes, what if i need to receive more? I would be reading each byte into a buffer as Bob has suggested in a previous post.

         

      thanks

        • 1. Re: interrupt on Uart
          user_1377889

          When you only want to have the bytes in a buffer, easiest will be to increase the Rx buffer size to your wanted size (plus some more bytes). The interrupt is handled internally and you can see how many bytes are already received by checking UART_GetRxBufferSize() which does not return the allocated buffer size, but the number of bytes received.

             

          When you want to retrieve the received bytes from the UART yourself, you will have to write a "Circular Buffer" yourself. The advantage is: You are able to react on a special character received, a delimiter as \n or \r, and set a flag when seen. This informs main() that a complete message has been received.

             

           

             

          Bob

          • 2. Re: interrupt on Uart
            cathal.ferrydl_1479341

            Hi Bob,

               

            thanks again for replying to my many threads. Cool so I need only increase the buffer size, for example if i know im receiving 6 bytes i just increase the rx buffer size to maybe 8 or 10 and i see the ISR is enabled now when its more than four bytes. I take it that its the same case for the tx buffer should i employ it?

               

            thanks Bob
             

            • 3. Re: interrupt on Uart
              cathal.ferrydl_1479341

              Ive also spotted the circular uart buffer you have made that was posted on the forums here. Ive been trying to test it on the PSoC 3, as I see its for the PsoC 4200, i think. Ive been attempting ot port it and pull in your main.c, myuart.c and myuart.h, Ive also made a note of your uart module settings. Ive been going through your main and header file. its really neat, i can see how it works.

                 

              However on rebuilding the project the compiler seems to have an issue with the structure definition where it reports a syntax error  here. The whole code seems to be like the pointers and structures exercise in linked lists ive done in C++, well except my linked list was a singly linked list then a double.

                 


                  union TRxBuffer {
                      char   RxStr[20];     // received Rx packet (to hold individual command message)
                      struct {             // anonimous structure
                          char cmd;         // 1-byte command
                          char valstr[19];  // command value           
                      };   ///here
                  } RB;  //here

              • 4. Re: interrupt on Uart
                user_1377889

                That's the curse using a PSoC3 and not 4 or 5  ;-) Quite an old design from 1980.

                   

                Try to experiment with the struct definition to get it error-free

                   

                 

                   

                Bob

                1 of 1 people found this helpful
                • 5. Re: interrupt on Uart
                  cathal.ferrydl_1479341

                  hmm i do have access to the 4200 and ble variant.

                     

                  I like the fact that a character can be used to uniquley identify a command. If I was implementing your code on a visual basic GUI for example, could i use the serial.portWriteline and send and 'A' for example and then send an int or float value? from using the standard Psoc 3 UART rx sample i was able to see on the LCD that an 'A' was received then a terminating character followed by my other data ie a number between 0 and 255. i didnt debug to see the ASCII hex equivalent but it think it was a CRLF.

                  • 6. Re: interrupt on Uart
                    user_1377889

                    Take care when transmitting items like 16 or 32-bit ints. I am not aware if the endianess of a PC (x86) is the same as for ARM.

                       

                    When using a PSoC4-M or a PSoC5LP prototyping kit you additionally have the opportunity to debug your code. Always worth the money!

                       

                     

                       

                    Bob

                    1 of 1 people found this helpful