Comments (11)
Fix those typos: initUSART()
, not initUsart()
; and receiveByte()
, not recieveByte()
.
from avr-programming.
I remember the same thing happening to me.
It looks like you are forgetting to include USART.c in your command line. Not sure what serial.c you're working with, but if it does an #include "USART.h", give this a try.
avr-gcc -g -mmcu=atmega328p -o serial.c USART.c serial.o
I'm still a beginner so if that doesnt work, ask the AVRFreaks forum. They usually respond within a couple hours....
/e
from avr-programming.
Thank you! Do I need to add USART.h as well? I did this:
avr-gcc -g -Os -DF_CPU=16000000UL -mmcu=atmega328p -c serial.c USART.c USART.h
then
avr-gcc -g -mmcu=atmega328p -o serial.elf serial.o
Do I need to add USART.elf and USART.o?
from avr-programming.
Scusi, here's the main file:
#include <avr/io.h>
#include <util/delay.h>
#include "pinDefines.h"
#include "USART.h"
int main(void){
char serialCharacter;
initUsart();
printString("test\r\n");
while(1){
serialCharacter=recieveByte();
transmitByte(serialCharacter);
}
return(0);
}
USART.h, USART.c and pinDefines.h are in the same directory.
from avr-programming.
The code looks fine -- you're just having trouble with the compiling/linking.
If you want to do the compilation by hand, the easiest way to go is to make sure that all the files you need (.h and .c) are all in the same directory. This works great for small personal projects.
Then you can compile simply with avr-gcc -Os -Wall -DF_CPU=16000000UL -DBAUD=9600UL -mmcu=atmega328p *.c -o serial.o
where if you want to be explicit, you can list out all the something.c files in place of the *.c
Because I reuse the serial libraries all over the place, I kept them in one place and linked to them. That ends up being all sorts of hassle -- you need to use the -I flag to tell the compiler where the .h files are located, and you need to specify a full path to the corresponding source files.
That, plus the other compilation options that are nice to use on the AVR platform, lead me to write up a makefile and use make for the book. It's a bit opaque for the beginner, which I don't like, but it should work more easily.
If I were re-doing it, I would consider simply copying the pinDefines.h and the USART.c and .h files into every directory that uses them. (You can do that yourself.) It's a horrible duplication of code, that makes any changes difficult to manage, but it's more straightforward.
from avr-programming.
Thank you for you reply, Elliot! I'm loving the book, thank you!!!
If I were re-doing it, I would consider simply copying the pinDefines.h and the USART.c and .h files into every directory that uses them.
Please don't do that. I like the way it is. Of course, it took me some time and research to figure out that I needed to add the files but this is how you learn. Again, I love the book, don't change a thing!
from avr-programming.
I've been trying to compile this project for days with no success. I cannot progress in the book if I can't compile these files. I've been trying to find information about compiling multiple files or at least some AVR tutorials with project files and there's hardly anything. I've tried
avr-gcc -Os -Wall -DF_CPU=16000000UL -DBAUD=9600UL -mmcu=atmega328p *.c -o serial.o
and it yields tons of errors:
alkopop79$ avr-gcc -Os -Wall -DF_CPU=16000000UL -DBAUD=9600UL -mmcu=atmega328p *.c -o serial.o
serial2.c: In function 'main':
serial2.c:10:1: warning: implicit declaration of function 'initUsart' [-Wimplicit-function-declaration]
initUsart();
^
serial2.c:14:2: warning: implicit declaration of function 'recieveByte' [-Wimplicit-function-declaration]
serialCharacter=recieveByte();
^
/var/folders/gw/2wc3kcqn7msdklf1hxdbyl4w0000gn/T//ccv7O3QW.o: In function `main':
serial2.c:(.text.startup+0x0): undefined reference to `initUsart'
serial2.c:(.text.startup+0xc): undefined reference to `recieveByte'
collect2: error: ld returned 1 exit status
Could anyone explain properly how to compile multiple files?
from avr-programming.
How embarrassing, thank you!
from avr-programming.
Hi,
I am having a similar issue. Here is whats happening:
- I am using USBasp
- I am using ATMega 328p
- I have been able to load blink examples usccesfully
- USART.c, USART.h, pinDefines.h are all in the same folder where serialLoopback.c is in.
- As we can see from the attached terminal screenshot, I am able to create *.o file, but error happens when trying to create *.elf file.
serialLoopback.c:
#include <avr/io.h>
#include <util/delay.h>
#include "pinDefines.h"
#include "USART.h"
int main(void) {
char serialCharacter;
LED_DDR = 0xff;
initUSART();
printString("Hello World!\r\n");
while (1) {
serialCharacter = receiveByte();
transmitByte(serialCharacter);
LED_PORT = serialCharacter;
}
return (0);
}
from avr-programming.
@sametron90 It looks like you need to point your linker to all the corresponding C files.
Try this:
avr-gcc -g -Os -mmcu=atmega328p -c serialLoopback.c USART.c serialLoopback.o
this will combine the code from serialLoopback.c and USART.c and spit it out into 1 object file.
also, before any of your #includes, write the line:
#define F_CPU 1000000UL
this will tell the chip how fast to run before calling any of the delay functions.
from avr-programming.
@rithma Thanks for the input, I think I got what you are conveying. I will try to include all the associated files and do the command.
from avr-programming.
Related Issues (20)
- pwmOnAnyPin: Incorrect register bit access
- Chapter 8 Interrupt code and serialScope do not match together
- Unclear statement Chapter 10: only 3 LEDs for hardware PWM when ATmega168PA has 6 HOT 1
- issue building makefile on ubuntu HOT 4
- Windows 10. avr-gcc and avrdude want different MCU strings
- USART.c ATmega16A fix.
- file not found error on first make attempt HOT 3
- When changing Makefile new hex is not generated
- question about makefile
- python code updated to python 3 HOT 4
- download zip fails with a 0kb download
- Lost the ability to receive bytes via USART by Chapter 9! HOT 1
- Issue with Serial Connection on Arduino HOT 2
- littlehacks.org - looks like it's down HOT 2
- compiler warnings atmel328p HOT 1
- avr 328p, crystal and leds HOT 1
- Magical number 3000 in servoWorkout.c (chapter 11)
- magical number 3000 in servoWorkout.c (chapter 11)
- examples 11-1 vs 11-2, prescaling and count speed HOT 1
- Some thoughts
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from avr-programming.