Eclipse IDE doesn't detect UART registers.

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello I try to run simple UART example on Atmega328P. I use Eclipse IDE with AVR plugin. It doesn't detect UART registers. I tried to include "iom328p.h" file where those are declared but then it tells that I include to many <avr/ioXXX.h> files. I tried to change names of registers deleting 0 and replacing it with 1 but it also didn't help. What's wrong?

 

Actual code:

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>

#include <stdio.h>

#define UART_BAUD 9600
#define __UBRR ((F_CPU+UART_BAUD*8UL) / (16UL*UART_BAUD)-1)

void UART_Init(uint32_t baud);
void UART_Transmit(char data);
unsigned char UART_Receive();
void UART_send_string(char* data);

int main()
{
	UART_Init(__UBRR);

	while(1)
	{
		UART_Transmit('a');
		_delay_ms(1000);
	}
}

void UART_Init(uint32_t baud)
{
	UCSR0B = (1 << RXEN0) | (1 << TXEN0);
	UCSR0C |= (1 << UCSZ01) | (1 << UCSZ00);

	UBRR0H = (uint8_t)(__UBRR >> 8);
	UBRR0L = (uint8_t)(__UBRR);
}

void UART_Transmit(char data)
{
	while(!(UCSR0A & (1 << UDRE0)));

	UDR0 = data;
}

void UART_send_string(char* data)
{
	char character;
	while((character = *data)){
		UART_Tramsmit(data);
		data++;
	}
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

tonn05 wrote:
Hello I try to run simple UART example on Atmega328P. I use Eclipse IDE with AVR plugin. It doesn't detect UART registers. I tried to include "iom328p.h" file where those are declared but then it tells that I include to many <avr/ioXXX.h> files. I tried to change names of registers deleting 0 and replacing it with 1 but it also didn't help. What's wrong?

 

You have probably specified a different AVR to Eclipse.   So avr/io.h has loaded a different header file for your target.

 

I admire your courage.   Eclipse makes my head hurt.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


What micro-controller did you select here:

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Or to put it another way if you build and look at the raw build output, when it invokes avr-gcc do you see it pass "-mmcu=atmega328p" ?

 

When -mmcu=atmeg328p is passed the preprocessor internally defines a symbol "__AVR_ATmega328P__". In turn, when you include <avr/io.h> when it then reaches:

...
#elif defined (__AVR_ATmega3250PA__)
#  include <avr/iom3250pa.h>
#elif defined (__AVR_ATmega328P__)
#  include <avr/iom328p.h>
#elif (defined __AVR_ATmega328__)
#include <avr/iom328.h>
#elif defined (__AVR_ATmega329__)
#  include <avr/iom329.h>
...

that will cause it to include the iom328p.h you need (but without the errors).

 

You should always use <avr/io.h> and some value in -mmcu= rather than doing this in any other way as that -mmcu= also has other knock-on consequences too.

 

Of course Eclipse (like many IDEs) may not know about the hidden mapping from -mmcu=atmega328p in the build options to the "hidden" definition of __AVR_Atmega328P__ by the pre-processor so it may not be able to see that iom328p.h is the header and set of symbols being defined. Some IDEs have a way to tell them how certain pre-pro symbols they cannot see are set to help in their source browsing and syntax highlighting (certainly Source Insight has this feature).

Last Edited: Tue. Jun 21, 2022 - 12:45 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yea, I have picked wrong microcontroller. Thanks. What other IDE do you recommend instead of Eclipse? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

tonn05 wrote:
What other IDE do you recommend instead of Eclipse? 

Microchip Studio 

 

OR

 

MPLAB X IDE

“Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?” - Brian W. Kernighan
“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” - Antoine de Saint-Exupery

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If it's Windows it has to be Studio 7. For anything else you should get by with MPLABX

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Dare to be naïve." - Buckminster Fuller

Last Edited: Wed. Jun 22, 2022 - 02:52 AM