'RXC' undeclared (first use in this function) ?

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

Guys,

Why do I get :
Error 12 'RXC' undeclared (first use in this function)

I used this library on other application and it's working, do I miss some libraries here ?

I'm using ATMEGA128 and the previous application is using the same as well ..

Any ideas ?
thanks

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

Quote:
Why do I get :
Error 12 'RXC' undeclared (first use in this function)
Because RXC doesn't exist in the chip you are trying to use but may exists in other chips.

So time to hit the datasheet, hint RXC cannot exist in the Mega128 as it has 2 USARTs.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

I'm using exactly the same chip and the same board, so what could it be ? do I miss a file here ?? a bit weird for me....

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

You start with a poorly framed question - you give it little context. I still have no idea of what error 12 is or what program generates it.
As John points out, the m128 has two usarts, so any reference is usually sufixed with a 0 or 1.
did you miss a file? Who knows?

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

You really should follow the advice given. Did you read the datasheet as suggested? I presume you found that there is no RXC because the chip has two UARTs and they are actually called RXC0 and RXC1. As such you could never have built code for a 128 that used "RXC" unless maybe it contained something like

#define RXC RXC0

(which isn't necessarily a great approach BTW).

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

That gives me an idea....., still feel strange, I can't find the define on the previous code but, it runs fine...anyway ..thanks

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

Here's my init :

void usart_init( unsigned int ubrr )
{
	/* Set baud rate */

	UBRR0H = (unsigned char)(ubrr>>8);
	UBRR0L = (unsigned char)ubrr;
	/* Enable receiver and transmitter */
	UCSR0B = (1<<RXEN)|(1<<TXEN);
	/* Set frame format: 8data, 2stop bit */
	UCSR0C = (1<<USBS)|(3<<UCSZ0);
}

and getting :

Error 7 'RXEN' undeclared (first use in this function)

from datasheet :

void USART_Init( unsigned int ubrr )
{
/* Set baud rate */
UBRRH = (unsigned char)(ubrr>>8);
UBRRL = (unsigned char)ubrr;
/* Enable receiver and transmitter */
UCSRB = (1<<RXEN)|(1<<TXEN);
/* Set frame format: 8data, 2stop bit */
UCSRC = (1<<USBS)|(3<<UCSZ0);
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Given what youve just been told about no RXC because of RXC0 and RXC1 can you guess what needs to happen to RXEN? (hint: it very likely involves a 0 or a 1).

(and I can see it's not just RXEN that needs this "porting").

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

Atmel has a nasty habit of copy/pasting code examples between data sheets. In some cases this makes the examples slighty wrong (although they amply describe how the code should be structured, and what needs to be done). This happens when they take a code example from an AVR with one USART and put it in a data sheet for an AVR with two USARTs.

What you need to do, and should always do, is to double check with the reference parts of the data sheet, in this case the register descriptions for the USARTs. There are two USARTs but they are identical apart for the actual register names (there will be a 0 or 1 in the names to keep the registers and bits for USARTo and USART1 apart.

Look at page 189 of the data sheet, and find a (general) description of the "USARTn Control and Status Register B – UCSRnB" (where you then need to replave the 'n' with '0' or '1' to match the USART you want to use). Read and think a bit and you will realize that you need to change the example to be

/* Enable receiver and transmitter */
UCSR1B = (1<<RXEN1)|(1<<TXEN1);

You will need to do similar changes to other parts of the example.

If your ATmega128 has the fuse set for Mega103 compatibility mode it will have only one USART available, the register and bit names will be different, you will have to read the ATmega103 data sheet instead/also, and you must set your compiler to build for an ATmega103 instead of an ATmega128.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]