Westporch
Westporch

Reputation: 817

ATmega128 - UCSROA undeclared (first use in this function)

I have a question about ATmega128 (UART) This program sends Hello message through UART.

The following is my code.

#include <avr/io.h>

void putch(unsigned char data)
{
    while((UCSROA & 0x20) == 0);
    UDR0 = data;
    UCSROA |= 0x20;
}

int main()
{
    unsigned char text[] = "Hello! World!\r\n";
    unsigned char i = 0;

    DDRE = 0xFE;
    UCSROA = 0x00;
    UCSROB = 0x18;
    UCSROC = 0x06;
    UBRROH = 0x00;
    UBRROL = 0x03;

    while(text[i] != '\0')
    putch(text[i++]);
    return 0;

}

This is error messages.

Build succeeded with 0 Warnings... 
avr-gcc  -mmcu=atmega128 -Wall -gdwarf-2 -std=gnu99   -DF_CPU=7372800UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT Hello.o -MF dep/Hello.o.d  -c  ../Hello.c 
../Hello.c: In function 'putch': 
../Hello.c:5: error: 'UCSROA' undeclared (first use in this function) 
../Hello.c:5: error: (Each undeclared identifier is reported only once 
../Hello.c:5: error: for each function it appears in.) 
../Hello.c: In function 'main': 
../Hello.c:16: error: 'UCSROA' undeclared (first use in this function) 
../Hello.c:17: error: 'UCSROB' undeclared (first use in this function) 
../Hello.c:18: error: 'UCSROC' undeclared (first use in this function) 
../Hello.c:19: error: 'UBRROH' undeclared (first use in this function) 
../Hello.c:20: error: 'UBRROL' undeclared (first use in this function) 
make: *** [Hello.o] Error 1 Build failed with 8 errors and 0 warnings...

I tested my code other computers.
But, It's not working.
I don't know how to fix this problem.

Give me some advice.
Thanks.

Upvotes: 1

Views: 1878

Answers (1)

Rev
Rev

Reputation: 6092

Its not

UCSROA

with the letter "O", it is

UCSR0A

with the number 0.

Upvotes: 0

Related Questions