using the USi to implment SPI

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

I needed to use a couple of HC595 on a Tiny2313 project. Multiple HC595s are cascaded together.

I created the a simple function based on the asm in the data sheets and post it here for others to use.

/*
Connecting the HC595 to the Tiny2313
Tiny2313		>>	HC595
SCK  	PB7 	>>	SCK,  Pin 11
MISO 	PB6		>>	SDI,  Pin 14
Latch	PB4		>>	RCK,  Pin 12
OP_Enb	PB3		>>	OPEnb,Pin 13 (active low)
+5v				>>	Reset,Pin 10

MOSI 	PB5		>>	No Connection

*/
#define PIN_OE			PB3
#define PIN_SS			PB4
#define PIN_MOSI 		PB5
#define PIN_MISO		PB6
#define PIN_SCK			PB7
#define HC595s			2			// number of HC595s in Serial register

/* Global Prototypes */
void send_spi_fast(int data);

The outputs of the HC595 can come up in an unknown state, so first we need to flush all 0s ( or 1s )
the code also shows how the function is called.

	/* Flush unknown output state of HC595 */
	for (l=0;l

This is the actual function implemented - it uses the fast method Fck/2

void send_spi_fast(int data)
{
	int i,j, USICRL, USICRH;

	USICRL = (1<<USIWM0) | (0<<USICS0) | (1<<USITC);  
	USICRH = (1<<USIWM0) | (0<<USICS0) | (1<<USITC) | (1<<USICLK);  

	USIDR = data;					// load data to be transferred via SPI 
	
	for(i=0;i<8;i++)				// transmitts 8 bits
	{
		USICR = USICRL;
		USICR = USICRH;
	}
	j = USIDR;	 					// put USI into slave mode
}

I hope this is useful to others.

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

Hi Matt, have you been hiding? :)

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

John,
Not at all just super busy with little time for my hobby.
Are you up for coffee?

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

Always up for coffee...and cake :) Just a little busy at the moment and one of the people I'm doing some work for snoops around this forum to see if I'm working or just spending the day here. :lol:

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly