POL
ENG

SPI interface on ATtiny2313 device

In my basement I have found one old project. It was remote controller with Attiny2313 in transmitter and Atmega8535 in receiver. It was using some dummy RF433MHz modules and wasn't able to send data properly. Probably that is way it was in basement ;). After a few years I decided to make it work by replacing those modules with something more intelligent. I decided to use RFM-70D. To communicte microcontroller with those modules you need to use SPI. So I downloaded datasheet for both and started implementing spi interface for smaller one. I went through all registers and setup them coretly, but for some reason, it wasn't working. I have spent two evenings with datasheet and logic analyzer and I couldn't force this small, black semiconductor to work. As probably most people, I sterted to search in the Internet for solution. Unfortunately, all I had found was some good advices from uncle Bob saying: "it must work", "it is easy", "when you configure register it will work", "I used it but I don't have code anymore". Yeah, right. Only on one page I have found working library. I wouldn't be my self if I didn't check what was wrong. Frankly speaking, I should write, what IS wrong, because this is still true.


while ((USISR & (1 << USIOIF)) == 0 ) {
  USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USICLK)|(1<<USITC);
}


block diagram


From this code and schematic above you can clearly see that USIDR (Universal Serial Interface Data Register) should be clocked by external clock signal. This is confirmed even by datasheet. In my first implementation I set up USICS1, USICS1 = 00 hoping that this will work, but it didn't.


clock select


So here are extremely simple C files. Grab it, use it, enoy!


Arien 2021-01-21
Very usefull listing ! Thank you very much.
James 2016-02-09
Thanks!
Add comment

ATtiny2313 spi interface, spi.c spi.h, AVR SPI, spi library for AVR

Wszelkie prawa zastrzeżone. Projekt i wykonanie strony SrcPro.pl