bit bang spi

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

Can anyone point me towards a down and dirty bit banged SPI? i need it for a 90s2313-to-d/a converter

the code i am doing is ugly and is way inefficient

any help would be great

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

Here is one that transfer 4 bytes from a flash table. You might need to modify it for your needs.

spi_driver:
	ldi	zh,0x20		;msb dsp values
	lds	zl,val_ptr		;load value	
	lsl	zl			;multiply
	lsl	zl			;by four
	ldi	ctr,4			;load byte ctr
spi_byte:
	lpm	flash,z+		;fetch byte
	sec				;set carry
	rol	flash			;shift in carry,bit 7 out
spi_bit:
	cbi	portc,spiclk	;spi clk lo
	brcc	spi_lo		;if carry clear bit lo
	sbi	portc,spibit	;else bit hi
	rjmp	spi_clk		;move on
	
spi_lo:
	cbi	portc,spibit	;bit lo
spi_clk:
	sbi	portc,spiclk	;spi clk hi
	lsl	flash			;until zero
	brne	spi_bit		;one more bit
	dec	ctr			;then until zero 
	brne	spi_byte		;one more byte	
	ret				;then return
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

what about AVR320: Software SPI Master ? (or is that the ugly code you are using?)

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

No, the code i was using came from my dopey brain

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

Lennart:

Thanks!!

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user