- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am a newbie with programming and I am having trouble getting my interrupts to work the way I want them to for my application. I want to send serial data over the UART to the PSoC, store the values every second, and then echo back the stored values. I am using a RX interrupt (RX FIFO not empty, priority 2) and a timer interrupt with the TC (priority 3). Attached is the TopDesign configuration. Currently, I am trying to get this code to work (just a sample code to see if I can get the interrupts to work correctly). I send the PSoC a string containing a character 'o', I should be reading only 'o' and '-', but the code always gets stuck in one of the interrupts with the other one never working. Could anyone tell me what I am doing incorrectly? Much appreciated!
Attached is the Top Design. The board is CY8CKIT-042
#include <project.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
uint16 ms_count = 0;
uint8 ch;
CY_ISR_PROTO(Timer_ISR);
CY_ISR_PROTO(RX_ISR);
CY_ISR(Timer_ISR){//Every millisecond, the code goes here
ms_count++;
if (ms_count == 1000){//Every second
ms_count = 0;
LED_Write(!LED_Read());
while(ch != 'o')UART_UartPutChar('-');
}
}
CY_ISR(RX_ISR){
uint8 status = UART_rx_ClearInterrupt();//Clear interrupt flag
uint8 sub;
sub = UART_UartGetChar();
if (sub != 0u){//Make sure grabbed character is not an empty
ch = sub;
if (ch == 'o'){
UART_UartPutChar(ch);
}
}
}
int main()
{
/* Start SCB UART TX+RX operation */
Timer_1_Start();
Time_ISR_StartEx(Timer_ISR);
RX_ISR_StartEx(RX_ISR);
CyGlobalIntEnable;
/* Start SCB UART TX+RX operation */
UART_Start();
UART_UartPutString("fdssf\n");
for(;;)
{
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Welcome in the forum, Eric.
Your timer runs 1ms interrupts, but sending a single char over your UART will take 40ms. This is a conflict.
Usually you need to avoid lengthy code in an interrupt handler, just set a flag and act on it in the main-loop.
All global variables which are changed in an interrupt handler must be declared as "volatile"!!
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey Bob,
Thanks for answering, really appreciate the help. Part of my project requirement is to make this real-time. Wouldn't setting a flag instead of handling it in the interrupt make this not real-time?
Also, the UART and the timer have a conflict in what sense? Do you mean that the there will be a growing queue of calls to the timer interrupt routine?
Also, the problem with my timer interrupt being stuck in the while loop still exists even though the RX interrupt has a higher priority and is receiving the correct characters to be able to transfer out of the while loop in the timer ISR. (Maybe it is the volatile variable?).
Many thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
erljiang,
Check if this SCB UART Rx demo for PSoC4 will work for you
http://www.cypress.com/comment/389231#comment-389231
From what I remeber, in this example PSoC4 UART receives a command from PC, extracts numerical value from it, and returns echo back to PC. Seems already close to your goal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks!