UART Question

Suraj143

Active Member
Can somebody tell me how this UART based RF module knows whether it receives data or transmits data?

This is an half duplex module.

I interface this with PIC.The module works sometimes only.

I think other times it is in the receiving mode when I send data...!!! how to detect that?
 

Attachments

Very good question.Yes they are between 1 meter.But I already checked placing them far away (20m) by powering two batteries.

Sometimes it will send data & sometimes not.

My only doubt is how this unit detects whether it is in transmit mode or receiving mode....!!!
 
Datasheet gives a clue.

Half duplex: Integration of receiver and transmitter,10ms auto change for receiving and sending.

This is the only thing they say regarding that
 
Datasheet gives a clue.

Half duplex: Integration of receiver and transmitter,10ms auto change for receiving and sending.

This is the only thing they say regarding that

When not transmitting, the standby/idle mode will be RX
 
10ms is next to nothing.


Connect the two units up with a serial cable... set it for Half Duplex... When you get it working. You then move back to radio..

Remember when using radio, you really need a packet style communication... Transmission loss is "par for the course" (inevitable).

In one area it may work flawless.... 2 metres to the left and its as choppy as the sea....
 


Here what I'm sending

Code:
Wait_TMR2	btfss	PIR1,TMR2IF		; 4mS rate
		goto	Wait_TMR2
		bcf	PIR1,TMR2IF
		decfsz	Counter,F		; 4 X 50 = 200mS
		goto	Wait_TMR2
		movlw	.50
		movwf	Counter
		;
		btfsc	PORTA,2			;
		goto	Wait_TMR2
		movlw	'D'			; identify character
		call	TX_232
		;
		movlw	'1'			; zone number
		call	TX_232
		goto	Wait_TMR2
;===============================================

TX_232		movwf	TXREG
		bsf	STATUS,RP0
		btfss	TXSTA,TRMT
		goto	$-1
		bcf	STATUS,RP0
		return

What do you mean by "10ms is next to nothing." ???
 
Here is the receiver code

Code:
Check_UART	btfss	PIR1,RCIF		; Is it a Recieve interrupt?
		goto	ISR_Exit
		movf	RCREG,W			; read the buffer
		andlw	b'01111111'
		movwf	RX_DATA			; load to a temperory register
		;
Check_String	btfss	Flag_Register,0
		goto	Check_D
		goto	Check_1
						
Check_D		movf	RX_DATA,W
		xorlw	'D'
		btfss	STATUS,Z
		goto	Reset_Field
		bsf	Flag_Register,0
		goto	ISR_Exit
			
Check_1		movf	RX_DATA,W
		xorlw	'1'
		btfss	STATUS,Z
		goto	Reset_Field
		bsf	Flag_Register,1
		;
		movf	Flag_Register,W
		xorlw	b'00000011'
		btfss	STATUS,Z
		goto	Reset_Field
		bsf	PORTA,2			; turn ON buzzer
		;
Reset_Field	clrf	Flag_Register
		;			
ISR_Exit
 
What do you mean by "10ms is next to nothing." ???
The time it takes you to process... Just make sure there is a 10mS delay in the code.

Like I said before... if you send a couple of characters.... and one gets lost, your receiver gets confused.


My basic packet contains " 0xAA , 0x55, d1,d2,.......d10, 0x7e, CRC "

So you know you have received a sensible packet of data... When I receive 0x7E I look down the buffer to check that 0xAA and 0x55 are in place. I then get the CRC and make sure the data is valid.

Then you know you are right... If you don't recieve a valid packet for more than 3 seconds.... "error"


Also you MUST check the USART module the thing may go into error and needs resetting.
 
Hi I added an error checking in my code is this ok?

Code:
Check_UART	btfss	PIR1,RCIF		; Is it a Recieve interrupt?
		goto	ISR_Exit
Check_Errors	movf	RCSTA,W
		andlw	b'00000110'
		btfsc	STATUS,Z
		goto	Read_UART
;-----------------------------------------------------	---------------------------------
Clear_OERR	bcf	RCSTA,CREN
		nop
		bsf	RCSTA,CREN
		;
Clear_FERR	movf	RCREG,W
		movf	RCREG,W
		movf	RCREG,W
		goto	Reset_Field
;--------------------------------------------------------------------------------------
Read_UART	movf	RCREG,W			; read the buffer
		andlw	b'01111111'
		movwf	RX_DATA			; load to a temperory register
			;
Check_String	btfss	Flag_Register,0
		goto	Check_D
		goto	Check_1
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…