Tiny261 and SPI

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

Hi all

Trying to get the SPI working on a Tiny261 with no luck at all. I've used AVRs with dedicated SPI modules before (Megas), but never with the USI instead. I have it connected to Port B, but can't see any action with a CRO on either Port B or Port A.

I've tried both Timer0 Compare and Software clock sources.

My code (copied from the datasheet):

SPI_INIT:							; initialise the SPI as master

	ldi		TEMP,		$24			; setup USI type and clock source (Timer0 Compare Match
	out		USICR,		TEMP		; output to USI control register

	ldi		TEMP,		$00			; setup USI pins (default PB0..2)
	out		USIPP,		TEMP

	ret

MAIN:

	ldi		r16,	$A1	;
	rcall	SPI_TRANSFER_FAST
	rjmp	MAIN			; loop



SPI_Transfer_Fast:

	out 	USIDR,r16

	ldi 	r16,(1<<USIWM1)|(0<<USICS0)|(1<<USITC)
	ldi 	r17,(1<<USIWM1)|(0<<USICS0)|(1<<USITC)|(1<<USICLK)

	out 	USICR,r16 ; MSB
	out 	USICR,r17
	out 	USICR,r16
	out 	USICR,r17
	out 	USICR,r16
	out 	USICR,r17
	out 	USICR,r16
	out 	USICR,r17
	out 	USICR,r16
	out 	USICR,r17
	out 	USICR,r16
	out 	USICR,r17
	out 	USICR,r16
	out 	USICR,r17
	out 	USICR,r16 ; LSB
	out		USICR,r17
	in		r16,USIDR
	
	ret

;***********************************************************************************

Any ideas? I'm not after high speed.

And my workshop has just been invaded by wasps, so I'm now sitting out in the carpark on the wifi waiting for a pest control dude to come save my AVRs.

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

Has been solved. Typical wiring error. MOSI and MISO labels refer to ISP programming, and hence my target tiny261 is the slave. Should have read further and seen the DO and DI labels are in fact backwards to the MOSI and MISO labels....

Now how to fix the PCB...

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

...and the wasps?

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

annoying double post.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Tue. Nov 25, 2008 - 08:08 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

guy came and took care of them. :)

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

So both the workshop and the boards are now bug-free. :lol:

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

No. Now the workshop has hundreds of dead bugs everywhere! Even after vacuuming I keep finding them everywhere.... Oh and the PCB, well still working on all the programming. But I'm now at home on the couch enjoying some bourbon. . . Happy me!