UART compiler problem

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

Hello,

Here is a function straight from the Atmel data sheet for the ATmega8:
void WriteUART(unsigned char data)
{
while(!(UCSRA & (1<<UDRE))); //Wait for empty transmit buffer
UDR = data; //Write data into the buffer and transmit
}

Now for the issue, is that my compiler is complaining that UDRE is undefined. It has no idea what UDRE is. I am using CodevisionAVR.

I know that the UDRE is bit 5 of the UCSRA register. Has anyone else had UDRE undefined and/or know of a workaround? Is there a way syntactically to read just bit 5 of the register?

Thanks much!

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

The examples in the datasheet(s) and most app notes are written for the IAR compiler.

The CodeVision chip include file Mega8.h has no bit definitions for any of the registers. We made enhanced chip include files for a number of the AVRs we used. It takes a lot of time poring over the datasheet to get it complete and correct. It will be a value judgement on your part whether it is worth it or not.

These are some defs I use that are correct for most AVRs. Be sure to carefully check with the datasheet before using.

Lee

/* UART Control Register UCSRB */
#define    RXCIE        7
#define    TXCIE        6
#define    UDRIE        5
#define    RXEN         4
#define    TXEN         3
#define    CHR9         2
#define    RXB8         1
#define    TXB8         0

/* UART Status Register UCSRA */
#define	RXC			7
#define	TXC			6
#define	UDRE		5
#define	FE			4
#define	OR			3
#define	U2X			1
#define MPCM		0

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Thanks! This should work as a fix for now:

void WriteUART(unsigned char data)
{
while(!(UCSRA & (1<<0x05))); //Wait for empty transmit buffer
UDR = data; //Write data into the buffer and transmit
}

I'll implement a new enhanced .h file.

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

Why don't you use the CodeVision Wizard to generate the sample/skeleton code for you? It then generates a set of define's for the commonly used UART expressions.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.