USART declaration problem (90USB1287)

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

Hello,

I am just trying to run a few samples for a serial project to get started and I keep getting declaration errors in regards to the uart registers.

Am I missing something or do I have to define these myself? It seems like I shouldn't have to.

Thanks

(code from here: http://winavr.scienceprog.com/avr-gcc-tutorial/avr-usart-explained.html)

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

Since you are using a AT90USB1287 you will find all the USART names have a '1' in them. e.g. RXC -> RXC1 and USARTC -> USART1C

Look up the register bit names in the data sheet. They are probably called RXCn and USARTnC .

Some AVRs have USARTs 0, 1, 2, 3 ...
The USB chips tend to only have one USART. Why they call it '1' is a mystery. Other chips with one USART call it '0'

Incidentally, you will only be able to get 115200 baud with certain crystal values. Try 9600 or 4800 baud. You can get this with almost any crystals.

David.

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

Excellent thank you, I saw that n in the data sheet but my brain misfired and I tried putting an n in the code not a n=1 which just makes sense. Although I now have also tried that and it doesn't work with 1 or 0? Any ideas?

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

Quote:
Any ideas?
Yes, I have a revolutionary idea:
post the error messages and the corresponding source code.

Stefan Ernst

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

I posted a link to the source code in my first post.
Here are the errors;

../uarttest.c:13: error: 'UBRRH1' undeclared (first use in this function)
../uarttest.c:13: error: (Each undeclared identifier is reported only once
../uarttest.c:13: error: for each function it appears in.)
../uarttest.c:14: error: 'UBRRL1' undeclared (first use in this function)

PS, no need to be snide, just ask or don't post.

edited*

Last Edited: Thu. Jan 12, 2012 - 08:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Solved. The datasheet example code is wrong.

It says "UBRRHn = (unsigned char)(baud>>8);"
but should say "UBRRnH = (unsigned char)(baud>>8);"

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

Yup. Too much confidence in the data sheet can be bad news.

Mind you. Other manufacturers can be a lot worse.

Since you are using GCC, click on the "iousb1287.h" file. You can check the correct spelling.

David.

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

Ok, I got that code to compile but it doesn't actually function. My setup is sending the signal to a ft232r which is connect to my pc and then I have hyper terminal setup.

I did a loopback test on the 232r and its good to go. But I get nothing out of the uC. Is there anything missing from that code I posted? I double checked it but it looks good. I am wondering if I missed some setup registers?

Also the code is unaltered other than changing the register names withthe ones where appropriate.

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

Without changing anything it started working but I am having baud rate problems. Thanks for the help :)