Author Topic: UART on Atmega328 using modified $50 code  (Read 3419 times)

0 Members and 1 Guest are viewing this topic.

Offline spizzakTopic starter

  • Full Member
  • ***
  • Posts: 102
  • Helpful? 1
UART on Atmega328 using modified $50 code
« on: July 26, 2009, 05:41:03 PM »
Once I do this step:

Open up your makefile, and add in rprintf.c and uart.c if it isn't already there:

# List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c a2d.c buffer.c rprintf.c uart.c

I get a bunch of errors in the UART.c file ... anyone have any idea what it is or what I'm doing wrong? I'm using the AVRISPII with an atmega328p.

Code: [Select]
Build started 26.7.2009 at 19:28:38

-------- begin --------
avr-gcc (WinAVR 20090313) 4.3.2
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Compiling: Photovore_v1.c
avr-gcc -c -mmcu=atmega328p -I. -gstabs   -O0 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=Photovore_v1.lst  -std=gnu99 -Wp,-M,-MP,-MT,Photovore_v1.o,-MF,.dep/Photovore_v1.o.d Photovore_v1.c -o Phot
ovore_v1.o


Compiling: a2d.c
avr-gcc -c -mmcu=atmega328p -I. -gstabs   -O0 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=a2d.lst  -std=gnu99 -Wp,-M,-MP,-MT,a2d.o,-MF,.dep/a2d.o.d a2d.c -o a2d.o
a2d.c:110: warning: 'SIG_ADC' appears to be a misspelled signal handler

Compiling: buffer.c
avr-gcc -c -mmcu=atmega328p -I. -gstabs   -O0 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=buffer.lst  -std=gnu99 -Wp,-M,-MP,-MT,buffer.o,-MF,.dep/buffer.o.d buffer.c -o buffer.o

Compiling: rprintf.c
avr-gcc -c -mmcu=atmega328p -I. -gstabs   -O0 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=rprintf.lst  -std=gnu99 -Wp,-M,-MP,-MT,rprintf.o,-MF,.dep/rprintf.o.d rprintf.c -o rprintf.o

Compiling: uart.c
avr-gcc -c -mmcu=atmega328p -I. -gstabs   -O0 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=uart.lst  -std=gnu99 -Wp,-M,-MP,-MT,uart.o,-MF,.dep/uart.o.d uart.c -o uart.o
uart.c: In function 'uartInit':
uart.c:52: error: 'UCR' undeclared (first use in this function)
uart.c:52: error: (Each undeclared identifier is reported only once
uart.c:52: error: for each function it appears in.)
uart.c:52: error: 'RXCIE' undeclared (first use in this function)
uart.c:52: error: 'TXCIE' undeclared (first use in this function)
uart.c:52: error: 'RXEN' undeclared (first use in this function)
uart.c:52: error: 'TXEN' undeclared (first use in this function)
uart.c: In function 'uartInitBuffers':
uart.c:70: warning: pointer targets in passing argument 2 of 'bufferInit' differ in signedness
uart.c:72: warning: pointer targets in passing argument 2 of 'bufferInit' differ in signedness
uart.c: In function 'uartSetBaudRate':
uart.c:93: error: 'UBRRL' undeclared (first use in this function)
uart.c: In function 'uartSendByte':
uart.c:119: error: 'UDR' undeclared (first use in this function)
uart.c: At top level:
uart.c:230: warning: 'SIG_UART_TRANS' appears to be a misspelled signal handler
uart.c: In function 'SIG_UART_TRANS':
uart.c:239: error: 'UDR' undeclared (first use in this function)
uart.c: At top level:
uart.c:258: warning: 'SIG_UART_RECV' appears to be a misspelled signal handler
uart.c: In function 'SIG_UART_RECV':
uart.c:263: error: 'UDR' undeclared (first use in this function)
make: *** [uart.o] Error 1
Build failed with 11 errors and 5 warnings...




And when I do this step:

Now after deciding on baud, in the file SoR_Utils.h (or in your main if you want) add the following code to your initialization (using your chosen BAUD rate):

uartInit();  // initialize UART
uartSetBaudRate(38400);// set UART baud rate
rprintfInit(uartSendByte);// initialize rprintf system


I get these errors:

Code: [Select]
Build started 26.7.2009 at 19:44:04

-------- begin --------
avr-gcc (WinAVR 20090313) 4.3.2
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Size before:
Photovore_v1.elf  :
section    size      addr
.text      1044         0
.bss          1   8388864
.stab      2784         0
.stabstr   3049         0
Total      6878




Compiling: Photovore_v1.c
avr-gcc -c -mmcu=atmega328p -I. -gstabs   -O0 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=Photovore_v1.lst  -std=gnu99 -Wp,-M,-MP,-MT,Photovore_v1.o,-MF,.dep/Photovore_v1.o.d Photovore_v1.c -o Phot
ovore_v1.o

In file included from Photovore_v1.c:3:
SoR_Utils.h:33: warning: data definition has no type or storage class
SoR_Utils.h:33: warning: type defaults to 'int' in declaration of 'uartInit'
SoR_Utils.h:33: warning: function declaration isn't a prototype
SoR_Utils.h:33: error: conflicting types for 'uartInit'
uart.h:165: error: previous declaration of 'uartInit' was here
SoR_Utils.h:34: error: expected declaration specifiers or '...' before numeric constant
SoR_Utils.h:34: warning: data definition has no type or storage class
SoR_Utils.h:34: warning: type defaults to 'int' in declaration of 'uartSetBaudRate'
SoR_Utils.h:34: warning: function declaration isn't a prototype
SoR_Utils.h:34: error: conflicting types for 'uartSetBaudRate'
uart.h:177: error: previous declaration of 'uartSetBaudRate' was here
SoR_Utils.h:35: warning: data definition has no type or storage class
SoR_Utils.h:35: warning: type defaults to 'int' in declaration of 'rprintfInit'
SoR_Utils.h:35: warning: parameter names (without types) in function declaration
SoR_Utils.h:35: error: conflicting types for 'rprintfInit'
rprintf.h:69: error: previous declaration of 'rprintfInit' was here
make: *** [Photovore_v1.o] Error 1
Build failed with 7 errors and 9 warnings...
« Last Edit: July 26, 2009, 05:45:54 PM by spizzak »

Offline apc3161

  • Jr. Member
  • **
  • Posts: 36
  • Helpful? 0
Re: UART on Atmega328 using modified $50 code
« Reply #1 on: July 26, 2009, 10:48:04 PM »

I just have a comment:

I've had an unbelievable amount of headaches dealing with those usart.c, adc.c, etc files. I find it actually much easier to learn how to just program the peripheral features on the device directly yourself for your application.

It's intimidating at first when you look at the code (if you aren't familiar with all the registers, numbers, letters, etc). But you end up learning a lot which is good, and it ALWAYS works. There are no headaches.

What I did was go through a lot of the AVR tutorial at avrfreaks.net and continuously reference the datasheet (kind of useless by itself for a novice, only useful when you know what it is talking about). Now I feel pretty comfortable writing ADC, USART, PWM, etc, code myself. I usually have very simply programs, and they seem to work great without any bugs or hiccups. Anyways, that is my advice.

Offline spizzakTopic starter

  • Full Member
  • ***
  • Posts: 102
  • Helpful? 1
Re: UART on Atmega328 using modified $50 code
« Reply #2 on: July 27, 2009, 07:07:10 AM »
Yeah I was actually thinking about doing that... I always have a lot of problems when trying to include other libraries in my programs.

Offline guncha

  • Jr. Member
  • **
  • Posts: 40
  • Helpful? 0
Re: UART on Atmega328 using modified $50 code
« Reply #3 on: July 27, 2009, 06:45:57 PM »
From your error it looks like the compiler can't find definitions in "uart.h". Did you include it in "main.c" ?

 


Get Your Ad Here