I created the following header file with definitions for AVR pins to be used in my code.
#define LED_PORT PORTB
#define LED_PIN PINB
#define LED_DDR DDRB
#define LED0 PB0
I encounter two failures I am not able to solve.
1) I have two issues in this header file, shown here:
2) Also the functions I created in the header file for USART in the USART.h file, I implemented, are not being recognized
I actually do not understand why that is. As the code clearly has the header file implemented.
#ifndef F_CPU
#define F_CPU 1000000UL
#endif
#include <avr/io.h>
#include <util/delay.h>
#include "pinDefinition.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);
}
The compiler I am using is AVR-GCC.
Furthermore, when I include the USART.c directly, then everything is working fine. I don't understand why the header file is not working though.
I created a script that runs the compiler/linker:
#!/bin/bash
avr-gcc -g -Os -mmcu=atmega328p -c code.c util.c USART.c
avr-gcc -g -mmcu=atmega328p -o code.elf code.o
avr-objcopy -j .text -j .data -O ihex code.elf code.hex
avr-size --format=avr --mcu=atmega328p code.elf
This returns the above mentioned error.
The USART.h looks like this:
/* These are defined for convenience */
#define USART_HAS_DATA bit_is_set(UCSR0A, RXC0)
#define USART_READY bit_is_set(UCSR0A, UDRE0)
#include <stdint.h>
void initUSART(void);
void transmitByte(uint8_t data);
uint8_t receiveByte(void);
void printString(const char myString[]);
void readString(char myString[], uint8_t maxLength);
void printByte(uint8_t byte);
void printWord(uint16_t word);
void printBinaryByte(uint8_t byte);
char nibbleToHex(uint8_t nibble);
char nibbleToHexCharacter(uint8_t nibble);
void printHexByte(uint8_t byte);
uint8_t getNumber(void);
I really require some help as I am trying to solve this now for three days and read a lot of different sources (I am getting my ropes together still with C so please be mindful).C