Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
10/20/07 19:00
Read: times


 
#145958 - Assembly bit bang code for Viculum SPI
Responding to: ???'s previous message
Hi Robert,

The following assembly SPI bit-bang routines seems to work with the Vinculum chip but you will still have to work out the other issues due to lack of documentation.

I have never posted code before so I hope I have used the formatting commands correctly.

I am happy to share this code with you but use this code at your own risk and let me know if you find any problems with the code.

Regards,

Bert


SCLK, CS, SDI, SDO are the port pins connected to the Vinculum I/O pins with the same name. The "nop's" are delays for timing and may not be needed depending on your crystal frequency.



;
;
;
GetSpiChar:		;Output 110 then clock in 8 bits plus 1 extra bit
	setb	CS	;Chip select high
	setb	SDI	;First bit sent to VDIP1 a "1" for 'READ'
	nop
	nop
	setb	SCLK	;clock in the 1st '1' bit
	nop
	nop
	clr	SCLK
	nop
	nop
	setb	SCLK	;clock in the 2nd '1' bit
	nop
	nop
	clr	SCLK
	clr	SDI	;'0' means read "Data" and '1' means reads "Status"
	nop
	nop
	setb	SCLK	;clock in the '0' bit
	nop
	nop
	clr	SCLK
;
;	Now clock in 8 bits plus 9th bit (to see if old or new data)
;
	mov	r0,#8	;bit counter
;
GCa:	mov	c,SDO	;read the data bit
	setb	SCLK
	nop
	rlc	a	;Most significant bit first
	clr	SCLK
	djnz	r0,GCa
	mov	c,SDO	;move 9th bit into C. 1=Old data, 0=New data
;
	clr	CS
	nop
	setb	SCLK
	nop
	nop
	clr	SCLK
	ret
;
;
;
SendSpiChar:		;Output '100' then clock out 8 bits of data
SCc:	push	acc
	setb	CS	;Chip select high
	setb	SDI	;First bit sent to VDIP1 a "1" for 'READ'
	nop
	setb	SCLK	;clock in the 1st '1' bit
	nop
	nop
	clr	SCLK
	clr	SDI
	nop
	setb	SCLK	;clock in a '0' bit
	nop
	nop
	clr	SCLK
	nop
	nop
	setb	SCLK	;clock in the '0' bit
;
;	Now clock out 8 bits of data
;
	mov	r0,#8	;bit counter
SCf:	clr	SCLK
	rlc	a
	mov	SDI,c	;write the data bit
	setb	SCLK
	djnz	r0,SCf
;
	clr	SCLK
	nop
	mov	c,SDO	;check if write was accepted or not
	setb	SCLK
	pop	acc
	clr	SCLK
	clr	CS
	nop
	jc	SCc	;write again if VDIP1 not ready	
	nop
	setb	SCLK
	nop
	nop
	clr	SCLK
	ret
;
;
;



List of 7 messages in thread
TopicAuthorDate
Vinculum VDIP with hardware SPI            01/01/70 00:00      
   it can't!            01/01/70 00:00      
      Thanks Erik            01/01/70 00:00      
   SPI on a VDIP            01/01/70 00:00      
      Interesting...            01/01/70 00:00      
   Assembly bit bang code for Viculum SPI            01/01/70 00:00      
      Thanks Bert            01/01/70 00:00      

Back to Subject List