This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

uart interrupt

hello dear all,
i am working on a project about uart interrupt. I want to send a hex file or number and show that on my LCD but i can't show any thing on my LCD i dont know whats my problem. i write my code, main part. i dont have example for uart interrupt and i hope you can help me.

_irq void UART2_IRQHandler(void){

unsigned s[8]; int i=0; char temp; do { temp = UART2_GetChar() ; s[i]=temp; i++;
} while(i<9);
return;}

main part:

int main (void)
{ int i=0; int j=0;
unsigned char lcd_buf[8];unsigned char s[8];

SystemInit(); UART0_Init(); UART2_Init(); LCD_Init(); NVIC_EnableIRQ(UART2_IRQn);

Load_Drow_Dialog(); while(1){

sprintf(lcd_buf,"counter: %d %d %d %d %d %d %d",s[0],s[1],s[2],s[3],s[4],s[5],s[6]); LCD_ShowString(0,30,lcd_buf );
i++; Delay(4000); }
}

Parents
  • If you spent a couple of minutes googling for UART ISR code, you would notice that a UART ISR isn't expected to busy-loop until a fixed number of characters has been received. It's instead expected to get activated when the UART wants to be serviced - and return as soon as the UART has no more need for service. Then if the UART recevies more data, the ISR can be activated again.

    If you are going to busy-loop, as your ISR does - then why not just busy-loop in the main code loop? Because a busy-loop within the ISR will kill all chances of getting lightning-quick responses.

    Another thing - when posting code there are clear instructions how to tag the code to make the post readable. Careful reading of instructions is a vital part of software development.

Reply
  • If you spent a couple of minutes googling for UART ISR code, you would notice that a UART ISR isn't expected to busy-loop until a fixed number of characters has been received. It's instead expected to get activated when the UART wants to be serviced - and return as soon as the UART has no more need for service. Then if the UART recevies more data, the ISR can be activated again.

    If you are going to busy-loop, as your ISR does - then why not just busy-loop in the main code loop? Because a busy-loop within the ISR will kill all chances of getting lightning-quick responses.

    Another thing - when posting code there are clear instructions how to tag the code to make the post readable. Careful reading of instructions is a vital part of software development.

Children
No data