RS232 not working with avr 2560

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

Anyone able to communicate with the RS232 on AVR 2560?
I have made some setup, but seems like I never get the RX complete interrupt (USART0_RX_vect).
I am using the Hyperterminal on the PC side, connected to the avr2560 using RS232 on COM1.

My setup is following:

/* Set baud rate */
UBRR0H = (unsigned char)(baudrate>>8);
UBRR0L = (unsigned char) baudrate;

/* Enable USART receiver and transmitter and receive complete interrupt */
UCSR0B = _BV(RXCIE0)|(1<<RXEN0)|(1<<TXEN0);

/* Set frame format: asynchronous, 8data, no parity, 1stop bit */
#ifdef URSEL0
UCSR0C = (1<<URSEL0)|(3<<UCSZ00);
#else
UCSR0C = (3<<UCSZ00);
#endif

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

Forget Rx for the time being - have you ever seen this AVR output anything sensible to the PC? If not I'd maybe take a look at FAQ#3 below

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

I was able to flash led's from different tasks, if that what you mean...

ulBaudRateCounter = ( configCPU_CLOCK_HZ / ( serBAUD_DIV_CONSTANT * ulWantedBaud ) ) - ( unsigned portLONG ) 1;

Where:
configCPU_CLOCK_HZ is 14745600UL
serBAUD_DIV_CONSTANT is 16
ulWantedBaud is 9600

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

Quote:
configCPU_CLOCK_HZ is 14745600UL

And my point was that the AVR may not be clocking at 14.7456MHz. Even if you have attached a crystal have you set CKSEL to enable it? If you have did you clear CKDIV8 at the same time?

The standard test is to sit in a loop transmitting 'U' at 9600 baud and measure the bit width - it should be 104us

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

Thanks!
I don't have a scope, cannot verify, anyone has the value for 2560?

BTW, is there any jumper settings needs to be done for the RS232?

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

Your questions don't make much sense.

What "value" are you talking about? If you mean the UBRRL value there's no doubt about it - the datasheet will tell you that if your AVR is clocking at 14.7456MHz (a big IF!) then the UBRR for 9600 is 95.

As for "jumper settings" - surely this completely depends on what piece of development electronics you are using. Hopefully it DOES have a MAX232 or equivalent between the AVR and the PC?

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

Okay, was able to get this working, well almost...
Seems like I am able to get characters, but only some characters are received (backspace, 1-7 etc).
Am using Hyper-Terminal.
Any clue?

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

Quote:

Seems like I am able to get characters, but only some characters are received (backspace, 1-7 etc).

You mean you just really receive "garbage" - this is almost certainly because the AVR is not clocking at the 14.7456MHz you think it is. There's some chance it may actually be running at 1.8432MHz (if the CKDIV8 fuse is set) so you could try setting UBRRL to 11

But I'm guessing the 2560 is really running at somewhere in the region of ~1MHz from its internal RC oscillator because you haven't set CKSEL or CKDIV8

This is the whole point of my FAQ#3 - you need to get the AVR running at the right speed for UART to to work.

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

Thanks.
What is the FAQ#3?
Can't find anything with regards to clocking using the link you put...