help with UART ISR

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi,

   

Ive been messing around with the UART function..... again. Ive implemented a simple ISR so on RX byte received which when triggered shows pn the LCD a message ISR, just to show it works.

   

I wanted to use the ISR to fill a buffer because i dont want other code to stop running while the PSoC is polling the uart rx.

   

I have a simple isr function and was wondering what would be the best way of filling a char array of size maybe 20 with some data in the correct order, then have the ISR exit and return back to code after that.

   

I can send a string to the PSOC with a  specific start command i.e an 'S' followed by a number but Id need to get that data into an array first before acting on it.

   

thanks guys

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Yepp, and you overflow your buffer because the variable i is never reset,

View solution in original post

0 Likes
9 Replies
lock attach
Attachments are accessible only for community members.
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

Cfcorp,

   

Attached is another incarnation of a project for reading UART into circular buffer. Use it as you wish
 

0 Likes
Anonymous
Not applicable

Hi again, thanks for the sample code. I have implemented a simple ISR for the rx data byte on the UART module.

   

It seems to read in data correctly, I am only reading in 8 bytes. I have the interrupt function check a 'flag' on data reception, In the main code I check if the flag is equal to 1 then read in the data. Ive since added an ADC function and I put a 100msec delay in the code. I notice that the delay messes up me reading in data. the delay seem to stall the CPU and misses the data being read, transmitting again seems to mostly work. Have i set up my interrupt incorrectly using the method ive implemented? Or is it that the delay of 100msec will always get in the way?

   

thanks guys

0 Likes
Anonymous
Not applicable

Hi,

   

Ive had some time to look at the UART ISR.

   

Ive seen some sample code that may apply and ive tried this routine although it doesn't work.

   

I only want to fill a small buffer called UART_Buffer that is a set size of 9 bytes for now.

   

it seems like it should work but it unfortunately doesn't

   

CY_ISR(Rcvd_byte)
{
  
    if(UART_1_ReadRxStatus() & UART_1_RX_STS_FIFO_NOTEMPTY)
    {
    UART_Buffer[i++] = UART_1_ReadRxData();
    }

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

There is something fishy with your interrupt handler. Can you please post your complete project, 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.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hi,

   

i have uploaded the project i was working on.

   

thank you

0 Likes
Anonymous
Not applicable

Hi,

   

That code is also missing  CyGlobalIntEnable;

   

Hmm must have deleted it by accident.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Yepp, and you overflow your buffer because the variable i is never reset,

0 Likes
Anonymous
Not applicable

Oh yes , i didnt notice that until now.

   

Im still having some issues, ive quickly changed the code. Its difficult to see the contents of the UART_buffer in debug mode.

   

while(UART_1_ReadRxStatus() & UART_1_RX_STS_FIFO_NOTEMPTY & i<=8)

   

{

   

UART_Buffer[i++]  = UART_1_ReadRxData();

   

}

   

i=0;

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

No, that will not work 😉 too fast changed, a loop waiting for 8 chars in the interrupt handler might stall your system.

   

Easiest:

   

Define an Rx buffer > 4 (use 20) and let the PSoC handle it with its internal interrupt. You may inspect GetBufferSize() in main() and see how many bytes are already in the buffer. When there are 8 bytes, you may start to read them off

   

 

   

Bob