I cannot get my serial connection running to test my AVR chip. I currently assume it is because of the F_CPU value, but I am not 100% sure. The manual error i defined for #error Systematischer Fehler der Baudrate größer 1%
appears when loading the program onto the chip. I don't know where to start right now finding the error. The console of my serial terminal does not show any output when connecting.
I created a config file I load in initially:
configGlobal.h
#ifndef F_CPU
#warning "F_CPU not yet defined, and will be set to 1MHz"
#define F_CPU 1000000UL
#endif
USART.c
#include "configGlobal.h"
#include <avr/io.h>
#include "USART.h"
#define BAUD 9600UL
#define BAUDRATE ((F_CPU) / (BAUD * 8UL) - 1) // set baud rate value for UBRR
void initUSART(void) {
// Requires BAUD
UBRR0H = (BAUDRATE >> 8) // Shift regisgter right by 8 bits to get upper 8 bits
UBRR0L = BAUDRATE;
UCSR0A |= (1 << U2X0);
// Enable USART
UCSR0B = (1 << TXEN0) | (1 << RXEN0); // Activate TX RX
UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); // 8 data bits, 1 stop bit
}
main.c
#include "configGlobal.h"
#include <avr/io.h>
#include <util/delay.h>
#include "USART.h"
int main(void) {
char serialCharacter;
// --- INITS --- //
DDRB = 0xff;
// Set up LED for output
initUSART();
printString("Hello World!\r\n");
return 0;
}
OUTPUT OF AVRDUDE
AVR Development Stack
Get input main.c file...
In file included from main.c:1:0:
configGlobal.h:2:2: warning: #warning "F_CPU not yet defined, and will be set to 1MHz" [-Wcpp]
#warning "F_CPU not yet defined, and will be set to 1MHz"
^
In file included from USART.c:1:0:
configGlobal.h:2:2: warning: #warning "F_CPU not yet defined, and will be set to 1MHz" [-Wcpp]
#warning "F_CPU not yet defined, and will be set to 1MHz"
^
In file included from /usr/local/CrossPack-AVR-20131216/avr/include/avr/io.h:99:0,
from USART.c:2:
USART.c: In function 'initUSART':
USART.c:10:2: error: called object is not a function or function pointer
UBRR0L = BAUDRATE;
^
Convert elf file to hex...
Uploading data to microcontroller...
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: Expected signature for ATmega328 is 1E 95 14
Double check chip, or use -F to override this check.
avrdude done. Thank you.