Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

ATTiny26: Using USI as UART // Issue

ATTiny26: Using USI as UART // Issue

2004-12-04 by David D. Rea

Hi Everyone-

First post here, so I humbly beg your pardon if this topic has been
discussed previously. I did a quick search through the message archives
and didn't turn anything up.

I'm working with the following setup:
	- ATTiny26 @ 1MHz
	- WinAVR for C development
	- ATAVRISP

I'm trying set up a simple means to get debug messages out of the micro.
Just dump the values of some ADC samples, etc. I found the Atmel appnote
regarding using the USI as a UART via Timer0 and the USI overflow
interrupt.

Sounded pretty cool, but their example with both Tx/Rx and buffering was
overkill for my needs. All I really need is a sendchar function. So I
figured I'd just implement their concept on my own, only the Tx side.
Besides, their example was written in IAR C, and I'm working with the
GNU avr-libc, so in the time it would have taken to port it, I figured I
could implement it myself.

Got quite a ways along with it, but I've got one problem (thus far at
least). The Timer0 counter register needs to be seeded with a value to
set the baud rate after each bit time. Got that working great, but as
soon as I enable the USI by setting its clock source to be the Timer0
overflow, it up and clears the interrupt flag and I've got no Timer0 ISR
to seed the timer any more! :(

The appnote doesn't seem to address this; it's written (evidently) under
the assumption that Timer0 can both clock the USI *and* fire off its own
ISR. Which must be the case... I'm just missing it somewhere in my
implementation.

Has anyone run across this? Or something similar?

Thanks in advance,
Dave
Upstate NY

Re: [AVR-Chat] ATTiny26: Using USI as UART // Issue

2004-12-04 by Leon Heller

----- Original Message ----- 
Show quoted textHide quoted text
From: David D. Rea
To: avr-chat@yahoogroups.com
Sent: Saturday, December 04, 2004 5:06 AM
Subject: [AVR-Chat] ATTiny26: Using USI as UART // Issue


Hi Everyone-

First post here, so I humbly beg your pardon if this topic has been
discussed previously. I did a quick search through the message archives
and didn't turn anything up.

I'm working with the following setup:
      - ATTiny26 @ 1MHz
      - WinAVR for C development
      - ATAVRISP

I'm trying set up a simple means to get debug messages out of the micro.
Just dump the values of some ADC samples, etc. I found the Atmel appnote
regarding using the USI as a UART via Timer0 and the USI overflow
interrupt.

Sounded pretty cool, but their example with both Tx/Rx and buffering was
overkill for my needs. All I really need is a sendchar function. So I
figured I'd just implement their concept on my own, only the Tx side.
Besides, their example was written in IAR C, and I'm working with the
GNU avr-libc, so in the time it would have taken to port it, I figured I
could implement it myself.

Got quite a ways along with it, but I've got one problem (thus far at
least). The Timer0 counter register needs to be seeded with a value to
set the baud rate after each bit time. Got that working great, but as
soon as I enable the USI by setting its clock source to be the Timer0
overflow, it up and clears the interrupt flag and I've got no Timer0 ISR
to seed the timer any more! :(

The appnote doesn't seem to address this; it's written (evidently) under
the assumption that Timer0 can both clock the USI *and* fire off its own
ISR. Which must be the case... I'm just missing it somewhere in my
implementation.

Has anyone run across this? Or something similar?


I was thinking of doing something similar with a Tiny11. I'd just use a 
simple software UART written in assmbler.

Leon

Re: ATTiny26: Using USI as UART // Issue

2004-12-04 by alan_probandt

I considered using the USI of the Tiny26 as a UART but abandoned the 
idea as too complex.  It would be better to use simple 'bit-banging' 
code for a 'softUART' that is already written.  
  Atmel's ap note on using the USI as a UART mentioned loading the 
start bit only into the USI serial register and transmitting it.  
Then the eight bit data followed by the stop bit.  Three seperate 
interrupt modes for the USI.  Then, they mentioned in passing at the 
end, you need to first invert the order of the bits in the byte 
because the USI transmits the most-significant bit first while a UART 
sends the least significant bit first.
  If you need both a UART and a SPI/I2C, then either a Tiny2313 or a 
Mega48 might be a better alterative model than the Tiny26.  The 
Mega48 has the ADC like the Tiny26.  Digikey has the Mega48 for 
$1.69, the Tiny26 for $1.55, and the Tiny2313 for $1.42 each in 
quantity 25 - DIP packages.

Alan Probandt
Portland, Oregon

Re: [AVR-Chat] Re: ATTiny26: Using USI as UART // Issue

2004-12-04 by David D. Rea

Thanks for the suggestions - I'm not yet comfortable with inline
assembly under C, so I doubt bit-banging is going to be feasible.

But I neglected to mention that this application doesn't need serial
functionality in production, only in development - so I'll probably dust
off one of my 90S4433 chips and use that for development, then do a
quick port over to the Tiny26 when I'm ready to burn down to the
production board...

Thanks again,
Dave
Show quoted textHide quoted text
On Sat, 2004-12-04 at 15:21, alan_probandt wrote:
> I considered using the USI of the Tiny26 as a UART but abandoned the 
> idea as too complex.  It would be better to use simple 'bit-banging' 
> code for a 'softUART' that is already written.  
>   Atmel's ap note on using the USI as a UART mentioned loading the 
> start bit only into the USI serial register and transmitting it.  
> Then the eight bit data followed by the stop bit.  Three seperate 
> interrupt modes for the USI.  Then, they mentioned in passing at the 
> end, you need to first invert the order of the bits in the byte 
> because the USI transmits the most-significant bit first while a UART 
> sends the least significant bit first.
>   If you need both a UART and a SPI/I2C, then either a Tiny2313 or a 
> Mega48 might be a better alterative model than the Tiny26.  The 
> Mega48 has the ADC like the Tiny26.  Digikey has the Mega48 for 
> $1.69, the Tiny26 for $1.55, and the Tiny2313 for $1.42 each in 
> quantity 25 - DIP packages.
> 
> Alan Probandt
> Portland, Oregon
> 
> 
> 
> 
> 
> 
> 
> 
>  
> Yahoo! Groups Links
> 
> 
> 
>  
> 
> 
> 
>

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.