Quantcast
Channel: Question and Answer » uart
Viewing all articles
Browse latest Browse all 57

I can't get out from interrupt driven serial communication

$
0
0

program works correctly but after receiving ‘#’ it has to come out from while loop and print “Exit” on lcd but it doesn’t.program still in while loop.

#define F_CPU 14745600
#include<avr/io.h>
#include<avr/interrupt.h>
#include<util/delay.h>
char data;
int ser=1;
void uart2_init(void)
{
   UCSR2B = 0x00; //disable while setting baud rate
   UCSR2A = 0x00;
   UCSR2C = 0x06;
   UBRR2L = 0x5F; //set baud rate lo
   UBRR2H = 0x00; //set baud rate hi
   UCSR2B = 0x98;
}

ISR(USART2_RX_vect)         // ISR for receive complete interrupt
{   
  data = UDR2;
  lcd_wr_char(data);    

  if(data=='#')
  { 
    ser=0;
  } 
}

void init_devices()
{
   cli(); //Clears the global interrupts

   lcd_port_config();
   uart2_init();

   sei();   //Enables the global interrupts
 }

//Main Function
int main(void)
{
  init_devices();
  lcd_set_4bit();
  lcd_init();
  while(ser);
  lcd_string("Exit");
}

Viewing all articles
Browse latest Browse all 57

Trending Articles