Avr serial not working on interrupt method

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

this works-

 

 

#include <avr/io.h>

 

int main(void)

{

DDRC=0xFF;

UBRRH=0X00;

UBRRL =0x67;

UCSRB= 0x10;

UCSRC=0x86;

while(1){

while(!(UCSRA & 0x80));

PORTC=UDR;

}

return(0);

}

 

 

this doesn't work-

 

 

#include <avr/io.h>

#include <avr/interrupt.h>

 

ISR(USART_RXC_vect)

{

PORTC=UDR;

}

 

int main(void)

{

DDRC=0xFF;

UBRRH=0X00;

UBRRL =0x67;

UCSRB= 0x90;

UCSRC=0x86;

sei();

while(1)

return(0);

}

It's textbook code,It sould have worked...Btw,I have an arduino connected to rx pin,sending 0 and 0xFF,alternativly to the target at 1 second interval.for output,I have an LED at portC, (pc1) ...when pin goes high,the led turns on. 

This topic has a solution.
Last Edited: Thu. Nov 9, 2017 - 01:55 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Raj69_71 wrote:
this doesn't work-
Because of a missing semicolon.

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Holy $@####

 

Thanks

Last Edited: Thu. Nov 9, 2017 - 01:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Try to get out of the habit of:

UCSRB= 0x90;
UCSRC=0x86;

No one (and that includes you in a few months) knows what bits you are trying to set here without digging out a datasheet.

 

Sure 0x90 = 0b10010000 but we still don't know what bit 7 and 4 actually are from this.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

How to properly post source code: http://www.avrfreaks.net/comment...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also, getting into the habit to always have braces with your if / else / while / for statements would keep you from this particular trap ...