Author Topic: Uart2.h  (Read 3341 times)

0 Members and 1 Guest are viewing this topic.

Offline CornelamTopic starter

  • Jr. Member
  • **
  • Posts: 24
  • Helpful? 0
  • I can smell a robot from a mile away
Uart2.h
« on: October 28, 2008, 01:34:21 AM »
i have a and i just can't compile his program!
I include uart2 in the makefile but it doesn't compile and the files uart2.h and uart2.c aren't created!
if i put them manually i get an error: uart2.c:167: error: 'UDRE' undeclared (first use in this function)
PLEASE HELP!!!
Thanks in advance!

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: Uart2.h
« Reply #1 on: October 28, 2008, 01:56:21 AM »
we need more details.
platform, compiler, target project, etc.

usually, that errors is raised when you port code for a single UART chip to a multi UART chip.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline CornelamTopic starter

  • Jr. Member
  • **
  • Posts: 24
  • Helpful? 0
  • I can smell a robot from a mile away
Re: Uart2.h
« Reply #2 on: October 28, 2008, 02:18:04 AM »
So i have a Atmega162. I program it with AVR Studio 4 and WinAvr. I have taken the code from the 50$ robot and modified it to work on the Atmega162.
The code works on everything except when i include the Uart2.c in the makefile.
When i do that it gives my this error: uart2.c:167: error: 'UDRE' undeclared (first use in this function)
Every time i try to make a new project when i'm compiling it gives me a error with something .elf even if i put the project name Photovore_v1 !
Please Help!
Thanks in advance!

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: Uart2.h
« Reply #3 on: October 28, 2008, 03:40:36 AM »
Just as I thought.
Atmega162 has multiple uarts, so, all UART registers have a number to determine what uart you are reffering to. Thus, UDRE is actually UDRE0 for UART 0 and UDRE1 for UART 1.
You will need to compare the datasheets of mega162 and mega8(i think that's the one used on the $50 robot), section UART, subsection registers, and see what is the equivalent of each register. Usually, it has the same name and ends with a number, but sometimes the number isn't right at the end.
For example, UDRE becomes UDRE0 (or 1, if you want to use UART1), UCSRA becomes UCSRA0 (or UCSR0A, I don't remember right).

You will need to do this in both uart.h and uart.c. A file-wise search-and-replace for each term should do it.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline CornelamTopic starter

  • Jr. Member
  • **
  • Posts: 24
  • Helpful? 0
  • I can smell a robot from a mile away
Re: Uart2.h
« Reply #4 on: October 28, 2008, 03:46:36 AM »
But i want to use both uarts!

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: Uart2.h
« Reply #5 on: October 28, 2008, 07:23:17 AM »
well then, you need two set of functions, for each uart.
copy uart.h and uart.c to two files, and edit (in each file) the registers to point to different uarts, then the function names, to inidicate what uart they operate on (init_uart1, uart2_out..)
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline CornelamTopic starter

  • Jr. Member
  • **
  • Posts: 24
  • Helpful? 0
  • I can smell a robot from a mile away
Re: Uart2.h
« Reply #6 on: October 28, 2008, 08:12:13 AM »
But what about uart2.h which is included in avrlib? why it gives me this error?
Apropo sunt si eu roman :D !
Thanks in advance!

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: Uart2.h
« Reply #7 on: October 28, 2008, 09:48:58 PM »
păi zi mă aşa :P
I don't work with avrlib that much, it's always easier to debug your own bugs than someone else's.
uart.h should be written in such a manner to detect if your device has a single or multiple uarts, and define functions accordingly. however, as you can see, it isn't. your device has two uarts, uart.h thinks it has only one (or it is written exclusively for devices with a single uart) in which case, register names don't match.

check admin's file for the axon, maybe there's something there, since the axon's mcu has two uarts.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Uart2.h
« Reply #8 on: October 30, 2008, 03:55:40 AM »
Follow the directions here about how to properly add the uart.c/uart2.c files:

http://www.societyofrobots.com/microcontroller_uart_50_robot.shtml

 


Get Your Ad Here

data_list