USART0 ATmega168 ASM compile problem

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

I must be going mad....

I'm re-purposing some ATMega8515 code to ATMega168 code and having problems in the USART area.

The standard code in the '168 datasheet for simple USART transmission is:

tx_uart:
	sbis	UCSR0A, UDRE0 ;<====line 63
	rjmp	tx_uart
 
	out	UDR0, r16 ;<====line 66
	ret

but that doesn't compile :(

...lib_util.asm(63): error: Operand 1 out of range: 0xc0
...lib_util.asm(66): error: Operand 1 out of range: 0xc6

..since in the 168 these registers are in upper register space and SBIS and OUT only work on regsisters 0-31

What gives?

EDIT: same problem with USART initialisation...

	out		UBRR0L, r16

:(

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

Aha!

The (apparently) old IN/LDS and OUT/STS gotcha - shame the '168 data sheet can't get it correct though :(

..if I'm correct, that is!

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

There is a note in the section "About Code Examples" (on page 8 in revision 'G') that for registers in the extended I/O map, certain opcodes must be replaced with others. Apparently it is too much trouble to put code that applies to the specific processor in the datasheets. (And I would have posted the entire paragraph if the datasheet was not copy protected).

Regards,
Steve A.

The Board helps those that help themselves.

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

Yeh, I found that this afternoon when I couldn't believe that Atmel would have put incorrect syntax in the code examples - but that was after I made a fool of myself here :lol: