๐Ÿ“ฃ๐Ÿ“ช ๐Ÿšš Adafruit will not be shipping USPS orders Monday October 14, 2019 ๐Ÿ—“. Expedited USPS orders placed after 11am ET ๐Ÿ•š Friday October 11 will go out Tuesday October 15 ๐Ÿ“ฃ๐Ÿ“ช๐Ÿšš
0

ATtiny2313 & USI howto?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

ATtiny2313 & USI howto?

by uhe on Tue Jun 10, 2008 3:14 pm

Hi

I'd like to use a MAX6979 (16 port LED driver) with a ATtiny2313.
But after studing the ATtiny datasheet I'm a little bit confused how this USI stuff works.

Has anyone a working example how to operate the 2313 USI in 3-wire mode?
uhe
 
Posts: 178
Joined: Mon Sep 03, 2007 4:50 pm
Location: metric world

by macegr on Tue Jun 10, 2008 6:36 pm

The datasheet is actually pretty straightforward. It contains assembly examples, but you can easily convert that to C. All you do is write your data byte into USIDR, set the bits in USICR to select the wire mode and clock settings, then toggle the USICLK bit in USICR to clock out the data. The USICR setting the example code is using on page 144 and 145 is exactly what you should use.
macegr
 
Posts: 292
Joined: Fri Apr 04, 2008 4:46 pm

by uhe on Thu Jun 12, 2008 6:01 pm

Jeah i know the datasheet pretty well but i have zero knowledge of avr assembly.
In between I found Atmels appnote
Code: Select all | TOGGLE FULL SIZE
AVR319: Using the USI module for SPI communication
which helps a lot!

I assume with only 8 bit the code i have will work but since i have to send 16bit the transmission get corrupted somehow.
I've no time for tests atm. (university..) but I'll report back when i have some news.
uhe
 
Posts: 178
Joined: Mon Sep 03, 2007 4:50 pm
Location: metric world

by macegr on Thu Jun 12, 2008 6:27 pm

For 16 bits you have to send it as two separate 8 bit transfers, the USIDR is one byte.
macegr
 
Posts: 292
Joined: Fri Apr 04, 2008 4:46 pm

by uhe on Wed Sep 24, 2008 3:56 pm

Finally i gave up using the USI. I'm not able to get a sane transfer, it's always messed up some how.
So i shift my data by hand basically like this if someone needs *a* solution:
Code: Select all | TOGGLE FULL SIZE
#define LE         _BV(PB4)
#define CLK      _BV(PB7)
#define DIN      _BV(PB6)
#define MASK       0x8000

void shiftByte(uint16_t wort)
{
   PORTB |= CLK;                  // high - init
   PORTB |= LE;                  // LE
   for (int i=0;i<16;i++) {
      USICR |= _BV(USITC);          // edge low
      MASK & wort ? (PORTB |= DIN) : (PORTB &= ~DIN);
      USICR |= _BV(USITC);          // edge high - save
      wort <<= 1;   
   }   
   PORTB &= ~LE;                  // !OE
}

The LE and !OE pins of the MAX6979 are connected together.
uhe
 
Posts: 178
Joined: Mon Sep 03, 2007 4:50 pm
Location: metric world

Please be positive and constructive with your questions and comments.