RF-24G working with 8051

I had a few 89C52 micro controllers that I wanted to use with some RF-24G modules, however the datasheet explains that the 89C51 would not work at 3 Volts. I could not find any information or sample source code in assembly for 8051 derivatives.

I got it to work at 3.3 volts. I didn’t think it was possible. If anyone wants the sample source here it is:

;-----------------------------------------------
; Nordic nRF2401A 2.4GHz Transceiver Software
;-----------------------------------------------
;
;Program starts out in RX mode, and monitors DR line
;if data comes in, print to terminal.
;To activate Transmit mode, press a key in terminal. This
;activates the uart interrupt and sets a flag to switch to
;TX mode and transmit data to the other RF24G.
;when you press any key in a terminal, you will see
;"0123456789" in the terminal connected to the receiving RF24G
;use any terminal program @9600 baud
;When done transmitting, RF24G returns to RX mode and
;monitors DR line for next data.
;
$nolist
$MOD51
$list
;
;-----------------------------------------------
CE		equ	p3.2		;
CS		equ	p3.3		;
DR1		equ	p3.4		;
CLK		equ	p3.5		;
DataLine	equ	p3.6		;

BitCnt	equ	08h	
ByteCnt	equ	09h

Flags	DATA	20h			; 
SerFlag	BIT	Flags.0	; flag to indicate RX'd byte from terminal
;
org 0
	jmp	Start			; 

org 23h
	jmp	Serial_Int		;
org 30h
;****************************************
Start:
	MOV	SP,#6FH		;Set Stack
	MOV	A,#0FFH		;
	MOV	P0,A			;  
	MOV	P1,A			;
	MOV	P2,A			;
	MOV	P3,A			;
	mov	Flags,#0		;
	call	Init_Uart

;config nRF2401A
	call	SendConfig		;clock out config string
	call 	Delay100mS
;****************************************
Main:
	jnb 	DR1,Main1		;if DR = High, data received
	call	RcvShockPkt
Main1:
	jnb 	SerFlag,Main	;only transmit if
	call	Transmit 		;char rec'd from terminal
	jmp	main
;****************************************
Transmit:
	call	TX_EN			;switch to TX mode
	call	Send_Pkt		
	clr	SerFlag
	call	RX_EN			;switch back to RX mode
	ret
;****************************************
;RF24G is configured for:
;RXEN, CHANNEL 2, RF Power: 0 DBm, 16MHz clock,Data Rate: 250 kbps,
;Shockburst Mode, One Channel Receive, 16 bit CRC enabled, 40 bit address,
;10 bytes payload length
;
SendConfig:
	clr	CE			; config mode
	setb	CS			; 
	lcall	Del_200uS		; 200uS delay

	mov	ByteCnt,#15		; # of bytes to send
	mov	dptr,#configword

Send_Loop:
	clr a
      movc a,@a+dptr		; get byte
	inc	dptr			; next byte
	call	SendByte		; send a byte from acc
	djnz	ByteCnt,Send_Loop	; Loop for all bytes in this SPI round

Send_Exit:
	setb	CE			; Enable Shockburst
	call	Delay10mS		; wait 10mS for TX
	clr	CE			; standby mode
	clr	CS			;
	clr	DataLine		; Data line low
	ret
;****************************************
SPIClock:
	setb	CLK
	nop
	nop
	clr	CLK
	ret
;****************************************
configword:
db 000h,050h,000h,000h,000h,000h,000h,0AAh
db 0BBh,0CCh,0DDh,0EEh,0A3h,04Fh,005h
;****************************************
ShockPacket:
db 0AAh,0BBh,0CCh,0DDh,0EEh,030h,031h,032h,033h,034h,035h,036h,037h,038h,039h
;****************************************
;send shockburst packet
Send_Pkt:					
	setb	CE			; enable TX (should be there already)
	call	Del_200uS		; 200uS delay

	mov	ByteCnt,#15		; # of bytes to send
	mov	dptr,#ShockPacket

BurstLoop1:
	clr a
      movc a,@a+dptr		; get byte
	inc	dptr			;
	call	SendByte		; send one byte
	djnz	ByteCnt,BurstLoop1 ; Loop until all bytes are sent

BurstReturn:
	clr	CE			; enable Shockburst
	call	Delay10mS		;
	clr	DataLine		; Data line low
	ret
;**************************************************
;send a byte from acc
SendByte:
	mov	BitCnt,#8		; Load number of bits in 'BitCnt'
SendByteLp:
	rlc	a			; shift left into c
	mov	DataLine,c		; send outgoing bit
	call	SPIClock
	djnz	BitCnt,SendByteLp	
	ret
;**************************************************
RcvShockPkt:	
	mov 	R0,#30h
	clr	ByteCnt

RxByteLp:	
	call	GetByte		; clock in 8 bits
	inc	ByteCnt		; next byte
	mov	@R0,a			; copy data in acc to rambuffer
	inc	R0
	
	jnb	DR1,RXShockExit	; check if DR1 is still high
	jmp	RxByteLp		; YES, get another byte
		
RXShockExit:
	nop			
	mov 	R0,#30h
SendLoop:
	mov	a,@R0			; copy data in rambuffer to acc
	inc	R0
	call	OutChar		; Print to terminal @9600 baud
	djnz	ByteCnt,SendLoop
	ret
;****************************************	
GetByte:
	mov	BitCnt,#8

GetByteLp:
	setb	CLK			; set clock high
	nop
	nop				;
	mov	c,DataLine		; get incoming bit
	rlc	a			; shift bit into carry

	clr	CLK			; set clock low
	nop				; 
	djnz	BitCnt,GetByteLp	; loop for 8 bits
	ret
;****************************************	
;switch to transmit mode
TX_EN:
	clr	CE		; 
	setb	CS		; config mode
	nop			; 5uS delay
	nop
	nop
	nop
	nop
	clr	DataLine	; disable bit 0 (RXEN)
	lcall	SPIClock	; clock it
	nop
	nop
	clr	CS		; Standby Mode
	clr	CE		;
	ret
;****************************************
;switch to receive mode
RX_EN:
	clr	CE		; config mode
	setb	CS		; 
	nop			; 5uS delay
	nop
	nop
	nop
	nop
	setb	DataLine	; enable RX (set bit 0)
	call	SPIClock	; clock it

	setb	CE		; active mode
	clr	CS		; 
	ret
;****************************************
Init_Uart:
	MOV SCON, #50h	; uart in mode 1 (8 bit), REN=1
	ORL TMOD, #20h	; Timer 1 in mode 2
	MOV TH1, #0FDh	; 9600 Baud at 11.059MHz
	MOV TL1, #0FDh	; 9600 Baud at 11.059MHz
	SETB ES		; Enable serial interrupt
	SETB EA		; Enable global interrupt
	SETB TR1		; Timer 1 run
	ret
;--------------------------------------------------------
;serial interrupt
Serial_Int:
	jnb 	RI,Exit_Int	; test if it is a reception
	clr 	RI 		; clear reception flag for next reception
	mov 	A,SBUF 	; read data from uart
	setb	SerFlag	; 
Exit_Int:
	reti
;--------------------------------------------------------
OutChar:
	mov	sbuf,a	;Load SBUF
	jnb	TI,$		;wait for last bit to transfer
	clr	TI		;get ready for next byte
	RET			;
;--------------------------------------------------------
Time1mS:
	MOV   r5,#2
      MOV   r4,#221
tim1mS:
	DJNZ  r4,$
      DJNZ  r5,tim1mS
      RET
;--------------------------------------------------------
;100mS @ 11.0592 MHz
Delay100mS:	
	mov	r6,#100
Del100mS:
	call	Time1mS
	djnz	r6,Del100mS
	ret
;--------------------------------------------------------
;10mS @ 11.0592 MHz
Delay10mS:
	mov	r6,#10
Del10mS:
	acall	Time1mS
	djnz	r6,Del10mS
	ret
;--------------------------------------------------------
;200uS @ 11.0592 MHz
Del_200uS:
	mov	r4,#89
	djnz	r4,$
	ret
;--------------------------------------------------------
END

just a very simple program that demonstrates how to use the modules.

I am pretty confident that this will also work with 89C2051, just comment out the two lines in the source code above.

it works for these modules here:

http://www.sparkfun.com/commerce/produc … cts_id=151

If anyone wants the entire project including the schematic & parts list look here:

http://rapidshare.com/files/187259466/RF24G_8051.zip

any advice or feedback is welcome.

newbie123 kindly reupload the entire project including the schematic & parts list. It will help me a lot to interface with 89c52.