Giter Site home page Giter Site logo

Comments (11)

baldowl avatar baldowl commented on July 24, 2024 1

Fix those typos: initUSART(), not initUsart(); and receiveByte(), not recieveByte().

from avr-programming.

rithma avatar rithma commented on July 24, 2024

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.

alkopop79 avatar alkopop79 commented on July 24, 2024

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.

alkopop79 avatar alkopop79 commented on July 24, 2024

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.

hexagon5un avatar hexagon5un commented on July 24, 2024

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.

alkopop79 avatar alkopop79 commented on July 24, 2024

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.

alkopop79 avatar alkopop79 commented on July 24, 2024

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.

alkopop79 avatar alkopop79 commented on July 24, 2024

How embarrassing, thank you!

from avr-programming.

sametron90 avatar sametron90 commented on July 24, 2024

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);
}

capture

from avr-programming.

rithma avatar rithma commented on July 24, 2024

@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.

sametron90 avatar sametron90 commented on July 24, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.