Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 5 > UART TX and RX interrupts

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



UART TX and RX interrupts
Moderator:
ANCY

Post Reply
Follow this topic



UART TX and RX interrupts

sstbrg posted on 07 Jun 2012 11:35 PM PST
Member
5 Forum Posts

 Hi, I'm new to PSOC and uC in general. I've used Atemga in the distant past but I pretty much forgot many concepts...

I just want to understand the theory here...

I'm implementing a UART in PSOC5 (CY8CKIT 001 dev kit).
I need to send 7-byte long messages to another circuit, which will, after about 100ns, return a 15-byte long answer.
I want to use an interrupt to indicate that a byte has been sent and another interrupt to receive the answer.

I configured the UART like so: buffers set to 16 bytes and 2 ISR components connected to the rx/tx_interrupt pins.
 

As far as I understand, when I have two interrupts with the same priority, in my case the TX interrupt will be generated at first, then after reading the status and clearing the interrupt, the program should jump to the second interrupt (RX received), read everything from the rx-fifo and return to main()... then if more bytes arrive, it will just jump tp the rx interrupt and repeat the reading process.... what do I need to do to accomplish this? Are there any example projects available with 2 interrupts acting like I described?

 

I hope my questions are clear, if not I'll be happy to explain myself :-)

 




Re: UART TX and RX interrupts

Bob Marlowe posted on 07 Jun 2012 01:32 AM PST
Top Contributor
1768 Forum Posts

The internal structure of the UART - implementation uses interrupts when you specify a buffer larger than 4 bytes (which is the size of the FIFO). These interrupts are called "internal". As you see, the Rx-OnByteReceived and Tx-OnFifoEmpty interrupt sources are greyed out when you use a buffer.

On the Rx-side the only interrupt-sources remain are dealing with errors or addresses

So when using buffered I/O you will have to poll the RX and TX-status to see what's going on

The advantage is that you may transfer your 7-byte message with a single API (UART_PutArray() ) to the UART which will handle the transfer.

There is an API to check the receive-buffer for the number bytes received.

 

To do-it-yourself:

In Schematic editor

your thoughts about the way the interrupts work looks quite right. To implement your own routines do the following:

Set the buffer-size back to 4 which will disable the internal interrupts

Select your wanted interrupt-source(s)

Connect two ISR-components to Rx/Tx interrupt terminals.

In main()

declare two routines with CY_ISR_PROTO (look into help -> Documentation -> System Reference -> System Ref. Guide)

define the two routines with CY_ISR

In initialization use ISR_StartEx(YourIsrRoutineName)

That's it.

Happy interrupting

Bob

 

 

 



Re: UART TX and RX interrupts

danaaknight posted on 07 Jun 2012 03:53 AM PST
Top Contributor
1773 Forum Posts

You could consider using 4 byte buffer, and 9 bit data, use 9'th bit as

a framing bit on 7 byte xmit and 15 byte reply.

 

Regards, Dana.



Re: UART TX and RX interrupts

sstbrg posted on 07 Jun 2012 04:17 AM PST
Member
5 Forum Posts

Thank you for the fast replies, guys!

Bob, I see what you mean about internal interrupts. I did some reading too before posting this, but for some reason your reply here cleared things up a bit more... What I've noticed during debugging is that the program jumps to the internal interrupt routines first and only after handling those, it jumps to my custom routines.

Now, let's say I'm disabling internal interrupts like you suggested, and declaring my own routines. Let's say the program jumps to my RX routine... I guess I need to tell the CPU that I've handled that interrupt... how do I do that? I could only find the 'clear pending interrupt' function in the ISR.c file... does it do the job or maybe I don't need to do anything? :S

I'm using UART_PutArray()  now... it makes things simpler for sure. However I do want use the tx interrupt for indication purposes only, like so: polling the status, checking that the interrupt was generated because TX is done, and lighting a LED or writing something on the LCD. Am I in the right direction?

Now about the buffers... say I'm setting the number of bytes in a buffer to 16. Can I simply poll the status of the RX buffer and check that there are 15 bytes in there (the packet which I received), then read those bytes one by one using a for loop or something? Another option might be using an interrupt to indicate that the RX buffer has received 15 bytes - is that possible?

Thanks again...

 

 



Re: UART TX and RX interrupts

sstbrg posted on 07 Jun 2012 04:19 AM PST
Member
5 Forum Posts

Sorry about the formatting of my reply above... it got completely screwed after posting for some reason...



Re: UART TX and RX interrupts

Bob Marlowe posted on 07 Jun 2012 06:11 AM PST
Top Contributor
1768 Forum Posts

As a general rule-of-thumb the handling of interrups should be as short as possible. As such common practice is just to set a global flag and return while the main() polls the flag, reacts on it and resets it at end-of-operation.

When using the ISR-component you do not have much to do, just take care to set the interrupt-type to "rising edge". The interrupt-controller is cared for.

Do not get irritated when debugging with having ISRs! When a breakpoint is reached, the CPU is halted, but the hardware is still running! So when a byte is transfered and you are at a breakpoint within the isr another int may become pending. when you continue running it will be priorized as usual. This may not show the normal unbreaked flow of control.

Do not write something on LCD within an Isr !!!!! Within the LCD-access there are some hard-coded delay routines which will postpone any other isr-handling. Poll for that in the main-loop.

Here is an untested(!!!) example of an UART project using two interrupts and providing a circular buffer for the received characters.



Re: UART TX and RX interrupts

kmmankad posted on 08 Jun 2012 06:35 PM PST
Top Contributor
268 Forum Posts

Hey,

I've written out some Interrupt based UART code tested on the CY8CKIT-030.

Check it out here https://github.com/kmmankad/UART-on-PSoC3

 

Regards,

kmmankad.



Re: UART TX and RX interrupts

sstbrg posted on 10 Jun 2012 03:31 AM PST
Member
5 Forum Posts

 Thank you guys, I'll check it out...

If more questions arise, I will reply here.

 

Thanks again.






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20