quickly looking at the schematic, I saw that you need to tie EA (Pin31 on the microcontroller) to VCC on both receiver and transmitter.
The reset circuit should have a 10uF capacitor and an 8.2K resistor. I could not tell the values from your schematic.
The capacitor values for the crystal should be 33pF (or less) not 33uF.
You should read this:
https://www.sparkfun.com/datasheets/RF/KLP_Walkthrough.pdf
To test whether or not your serial routines are working, have the transmitter send data to the PC use the attached terminal program. You will need a maxim 232 driver in your circuit connected to the TX and RX lines of the microcontroller.
here is a small routine you can use:
Code:;********************************************* ;UART Test code $mod51 ;this one uses UART hardware to TX @2400 Baud ;timing is adapted for 11.0592 MHz crystal ;**************************************************** org 00000h Reset: sjmp Start ;reset vector Start: MOV SP,#70h ; Start stack near top of '51 RAM. mov a,#0FFh ; clear Ports mov p1,a ; mov p3,a ; ;------Initialize Uart------------ MOV SCON,#01010000B ;(50H) Mode 1/Rec en ; bit 4 = REN receive enable ; bit 6 = mode 1. - 8 bit uart variable baud rate ;; MOV TH1,#0E8H ; Reload value for 1200 Bd @11.0592 MHz MOV TH1,#0F4H ; Reload value for 2400 Bd @11.0592 MHz ;; MOV TH1,#0FAH ; Reload value for 4800 Bd @11.0592 MHz MOV TMOD,#00100000B ; (21H) Gate1/Timer/Mode 2 / Gate0/Timer/Mode 1 ; bit 5 = 8 bit auto reload for timer 1 (Mode2) setb TR1 ; start timer 1 ;---------------------------------------------- Main: clr a Main1: lcall transmit inc acc acall Time1mS sjmp Main1 ;---------------------------------------------- Time1mS: MOV R2,#2 MOV R1,#221 tim1mS: DJNZ R1,$ DJNZ R2,tim1mS RET ;---------------------------------------------- transmit: MOV SBUF,A JNB TI,$ CLR TI ret ;---------------------------------------------- end
use the attached terminal program and set the input to hex (not ascii)
connect at 2400 baud and you will see it works.
then you can test the receiving code. All you have to do is type in a character in the terminal and press send, this code will return the value you sent back to the terminal.
Code:;********************************************* ;UART Test receiver code $mod51 ;this one uses hardware uart to receive @2400 Baud ;timing is adapted for 11.0592 MHz clock ; ;port 3 pinouts ;---------------------------------------------------- org 00000h Reset: sjmp Start ; reset vector Start: MOV SP,#070h ; Set up stack pointer mov a,#0FFh ; clear Ports mov p1,a ; mov p3,a ; ;------Initialize Uart------------ MOV SCON,#01010000B ;(50H) Mode 1/Rec en ; bit 4 = REN receive enable ; bit 6 = mode 1. - 8 bit uart variable baud rate ;; MOV TH1,#0E8H ; Reload value for 1200 Bd @11.0592 MHz MOV TH1,#0F4H ; Reload value for 2400 Bd @11.0592 MHz ;; MOV TH1,#0FAH ; Reload value for 4800 Bd @11.0592 MHz MOV TMOD,#00100000B ; (21H) Gate1/Timer/Mode 2 / Gate0/Timer/Mode 1 ; bit 5 = 8 bit auto reload for timer 1 (Mode2) setb TR1 ; start timer 1 ;---------------------------------------------- Main: lcall receive ;receive data from terminal lcall transmit ;echo it back to terminal sjmp Main ;---------------------------------------------- ; Receive a character and return in ACC receive: JNB RI,$ ;wait here for receive int MOV A,SBUF ;get data CLR RI ;clear receive int ret ;---------------------------------------------- ;Transmit a character from ACC transmit: MOV SBUF,A JNB TI,$ CLR TI ret ;---------------------------------------------- end
If that works, then you know your hardware is perfect. Then just change the TX & RX lines back to the RF modules and test the same code.
Remember the receiver ALWAYS receives data, no matter what it is, noise, etc.
In my code I filtered out the incoming data like this:
Code:Main1: lcall receive ;receive data from uart cjne a,#099h,Main1 ;compare received byte with 99h ;if its different, restart mov 08h,a ;save first byte received ;we are here because first received byte compares to 0x99 lcall receive ;get second byte ;------------- cjne a,#088h,Main1 ;compare received byte with 88h mov 09h,a ;save second byte received ;next the program gets two more bytes (total 4 bytes) ;then xor first three bytes together ;then compare last byte with xor value of 3 first bytes ;not the same? go back to Main1 ;this way you are SURE that your receiving code won't pick up garbage bytes. ;I mean it always will, but you must ignore the garbage.
Let me know how it goes.
quickly looking at the schematic, I saw that you need to tie EA (Pin31 on the microcontroller) to VCC on both receiver and transmitter.
The reset circuit should have a 10uF capacitor and an 8.2K resistor. I could not tell the values from your schematic.
The capacitor values for the crystal should be 33pF (or less) not 33uF.
You should read this:
https://www.sparkfun.com/datasheets/RF/KLP_Walkthrough.pdf
To test whether or not your serial routines are working, have the transmitter send data to the PC use the attached terminal program. You will need a maxim 232 driver in your circuit connected to the TX and RX lines of the microcontroller.
here is a small routine you can use:
Code:;********************************************* ;UART Test code $mod51 ;this one uses UART hardware to TX @2400 Baud ;timing is adapted for 11.0592 MHz crystal ;**************************************************** org 00000h Reset: sjmp Start ;reset vector Start: MOV SP,#70h ; Start stack near top of '51 RAM. mov a,#0FFh ; clear Ports mov p1,a ; mov p3,a ; ;------Initialize Uart------------ MOV SCON,#01010000B ;(50H) Mode 1/Rec en ; bit 4 = REN receive enable ; bit 6 = mode 1. - 8 bit uart variable baud rate ;; MOV TH1,#0E8H ; Reload value for 1200 Bd @11.0592 MHz MOV TH1,#0F4H ; Reload value for 2400 Bd @11.0592 MHz ;; MOV TH1,#0FAH ; Reload value for 4800 Bd @11.0592 MHz MOV TMOD,#00100000B ; (21H) Gate1/Timer/Mode 2 / Gate0/Timer/Mode 1 ; bit 5 = 8 bit auto reload for timer 1 (Mode2) setb TR1 ; start timer 1 ;---------------------------------------------- Main: clr a Main1: lcall transmit inc acc acall Time1mS sjmp Main1 ;---------------------------------------------- Time1mS: MOV R2,#2 MOV R1,#221 tim1mS: DJNZ R1,$ DJNZ R2,tim1mS RET ;---------------------------------------------- transmit: MOV SBUF,A JNB TI,$ CLR TI ret ;---------------------------------------------- end
use the attached terminal program and set the input to hex (not ascii)
connect at 2400 baud and you will see it works.
then you can test the receiving code. All you have to do is type in a character in the terminal and press send, this code will return the value you sent back to the terminal.
Code:;********************************************* ;UART Test receiver code $mod51 ;this one uses hardware uart to receive @2400 Baud ;timing is adapted for 11.0592 MHz clock ; ;port 3 pinouts ;---------------------------------------------------- org 00000h Reset: sjmp Start ; reset vector Start: MOV SP,#070h ; Set up stack pointer mov a,#0FFh ; clear Ports mov p1,a ; mov p3,a ; ;------Initialize Uart------------ MOV SCON,#01010000B ;(50H) Mode 1/Rec en ; bit 4 = REN receive enable ; bit 6 = mode 1. - 8 bit uart variable baud rate ;; MOV TH1,#0E8H ; Reload value for 1200 Bd @11.0592 MHz MOV TH1,#0F4H ; Reload value for 2400 Bd @11.0592 MHz ;; MOV TH1,#0FAH ; Reload value for 4800 Bd @11.0592 MHz MOV TMOD,#00100000B ; (21H) Gate1/Timer/Mode 2 / Gate0/Timer/Mode 1 ; bit 5 = 8 bit auto reload for timer 1 (Mode2) setb TR1 ; start timer 1 ;---------------------------------------------- Main: lcall receive ;receive data from terminal lcall transmit ;echo it back to terminal sjmp Main ;---------------------------------------------- ; Receive a character and return in ACC receive: JNB RI,$ ;wait here for receive int MOV A,SBUF ;get data CLR RI ;clear receive int ret ;---------------------------------------------- ;Transmit a character from ACC transmit: MOV SBUF,A JNB TI,$ CLR TI ret ;---------------------------------------------- end
If that works, then you know your hardware is perfect. Then just change the TX & RX lines back to the RF modules and test the same code.
Remember the receiver ALWAYS receives data, no matter what it is, noise, etc.
In my code I filtered out the incoming data like this:
Code:Main1: lcall receive ;receive data from uart cjne a,#099h,Main1 ;compare received byte with 99h ;if its different, restart mov 08h,a ;save first byte received ;we are here because first received byte compares to 0x99 lcall receive ;get second byte ;------------- cjne a,#088h,Main1 ;compare received byte with 88h mov 09h,a ;save second byte received ;next the program gets two more bytes (total 4 bytes) ;then xor first three bytes together ;then compare last byte with xor value of 3 first bytes ;not the same? go back to Main1 ;this way you are SURE that your receiving code won't pick up garbage bytes. ;I mean it always will, but you must ignore the garbage.
Let me know how it goes.
Can you let me know the third and fourth byte to be checked. Or are they the data bytes. I checked random data for 3rd and 4th byte but I'm not able to verify the authenticity of the data recieved.
They are whatever you want them to be. That is, the receiver must match what the transmitter sends.it is stated that the program gets two more bytes (total 4 bytes).
My doubt is what are these bytes?
They are whatever you want them to be. That is, the receiver must match what the transmitter sends.
Look at post # 16. Another guy did the same thing you are trying to do. Read the entire thread on 8052.com before attempting to do this.
Download the code here:
**broken link removed**
hey cud you plzz tell me if it is necessary to use max232 ic to interface mcu with a tx rx pair...
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?