Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

using on chip SPI in P89V51RD2

Status
Not open for further replies.

rajeshbij

Member level 1
Joined
Feb 9, 2007
Messages
33
Helped
4
Reputation
8
Reaction score
2
Trophy points
1,288
Location
Jaipur, INDIA
Activity points
1,468
I want to use the in built SPI functionality of P89V51RD2. How to implement it?
Pls guide me.
 

Did you want someone to write the code for you?
READ page 39 of the datasheet then post the code you wrote here so others can help you.

ctownsend I did not mean someone to write code for me.
I understand the bit-banging for implementing the SPI, but saw in built provision in 89v51rd2 which means no need for bit-bang.
I also had read the data sheet as you mentioned, but am confused how to implement it, it must be done on byte level - I suppose.
To my understanding, there should be some register like the SBUF for UART to send/receive bits and reassemble.
may pls provide the logic or psedo-code so that I can understand the implementation better.
 

here you go. This works on an ATMEL AT89C51ED2. Not 100% sure it will work for the Phillips equivalent.

Code:
SPI_Temp	equ	08h		;temporary SPI Data Byte

;	mov SPCON,#10010110b	; Fclk Periph/128, Master Mode, SPI Mode 3
	mov SPCON,#10110101b	; same as above except Fclk Periph/64

	orl SPCON,#40h		; start spi
;--------------------------------------------------------------
	mov	r7,#0			; start data @ 00h
loop:             		
	mov SPI_Temp,r7		;
	lcall	SendSPI		;	
	lcall	Delay1mS

	inc r7			;send 0h - 0FFh to SPI
	mov a,r7
	jnz loop

	xrl SPCON,#40h		; disable spi

stop:
	sjmp	stop
;--------------------------------------------------------------
;send SPI data from SPI_Temp, returns read SPI data in SPI_Temp
SendSPI:
	mov SPDAT,SPI_Temp	;transmit SPI Data

WaitSPI:
	mov a,SPSTA
	jnb acc.7,WaitSPI		;wait for TX complete before reading

	mov SPI_Temp,SPDAT	;read SPI Data
	ret

Just glanced a the Phillips data sheet. The above will not work on the Phillips 89V device without modification of the SFR names and the configuration. Since I do not have a phillips device I cannot test any modifications. However, try this:
Code:
SPCTL		EQU	0D5h
SPCFG		EQU	0AAh
SPDAT		EQU	086h
SPI_Temp	equ	08h		;temporary SPI Data Byte


	mov SPCTL,#01010011b	; Fosc /128, Master Mode, SPI Mode 3
;--------------------------------------------------------------
	mov	r7,#0			; start data @ 00h
loop:             		
	mov SPI_Temp,r7		;
	lcall	SendSPI		;	
	lcall	Delay1mS

	inc r7			;send 0h - 0FFh to SPI
	mov a,r7
	jnz loop

	xrl SPCTL,#40h		; disable spi

stop:
	sjmp	stop
;--------------------------------------------------------------
;send SPI data from SPI_Temp, returns read SPI data in SPI_Temp
SendSPI:
	mov SPDAT,SPI_Temp	;transmit SPI Data

WaitSPI:
	mov a,SPCFG
	jnb acc.7,WaitSPI		;wait for TX complete before reading

	mov SPI_Temp,SPDAT	;read SPI Data
	ret
 
Last edited:
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top