Problem with USI

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have the following code


//************************************ include ***********************************
.include "tn45def.inc"

//************************************ variables *********************************
.def USI1 = r16
.def USI2 = r17
.def DATA = r18

.def reg1 = r25


//************************************ vectors ***********************************
RESET:
{
	ldi reg1,HIGH(RAMEND)
	out SPH,reg1
	ldi reg1,LOW(RAMEND)
	out SPL,reg1
	rjmp MAIN
}

//************************************ main program ******************************
MAIN:
{
	rcall init
	ldi DATA, 0x55

	for:	
	{
		rcall SPITransfer
		rjmp for
	}
}

SPITransfer:
{	
	out USIDR, DATA
	nop

	ldi	USI1,(1<<USIWM0) | (0<<USICS0) | (1<<USITC)
	ldi	USI2,(1<<USIWM0) | (0<<USICS0) | (1<<USITC) | (1<<USICLK)

	out USICR, USI1
	out USICR, USI2

	out USICR, USI1
	out USICR, USI2

	out USICR, USI1
	out USICR, USI2

	out USICR, USI1
	out USICR, USI2

	out USICR, USI1
	out USICR, USI2

	out USICR, USI1
	out USICR, USI2

	out USICR, USI1
	out USICR, USI2

	out USICR, USI1
	out USICR, USI2

	ret
}

init:
{
	ldi reg1,0x06
	out DDRB,reg1

	sei
	ret
}

and I am wanting to change the value of data, but when I do, it seems to mess the usi up really bad, to the point of not being able to recognize anything coming across. If I just pick one character to send out repeatedly, like this code does, then it works fine. What am I screwing up?