UART 9 Bit Reception.

Status
Not open for further replies.

Suraj143

Active Member
What is ADDEN bit in UART RCSTA ? What it does.I'm going to do a 9bit reception will this bit help?
 
It depends on your use of the serial interface. I'm going to guess that you wont want to use it for your project.
The address detect enable bit is often used (but not exclusively) by a serial bus arrangement (ie rs485) where a master uC might talk to many slave uCs.
In that case the ninth bit is used to give a byte particular significance. In most cases the significance is that a byte with a logic one found in the ninth bit is an address byte.

The receiving microcontroller should check the byte to see if it matches its own address. If it doesn't, the slave uC can go back to idle/sleep or whatever it was doing and ignore subsequent bytes where the ninth bit is 0.

if it does match, the receiving uC deals with the subsequent bytes coming from the master (might be a command or data or both).

In other cases the ADDEN bit can just be used to resynchronise your serial software handler state machine. It can be used just to signify the beginning of a serial data stream. Some serial protocols use a "break" or idle time to resync master<->slave comms but sometimes this is precious time wasted and using a ninth bit as a resync flag is preferred.

If you're using the ninth bit as parity or just as an extra data bit, you're not going to want to use the ADDEN function


John Dowdell
 
Last edited:
Hello mr Dowdell.thanks for the wonderfull reply.

i'm doing a master slave comunication using UART.i have 1 master & 13 slaves.what i need is a technic to address the slaves.does that ADDEN gives a seperate address byte (16 bits frame 2bytes)?
 
This is what I understood tell me is this ok?

* Master will transmit slave address, make 8th bit high to make this an address byte.

* Slave will recieve this data.If it is a address byte then read it & match with the slave address.

* If it matches then transmit slave address followed by data byte (PORTB data).

* Master will recieve only slave address (first byte) because ADDEN = 1.If the slave address match then
make ADDEN=0 & read RCREG to read the PORTB data.
 
Last edited:
The method you have listed there sounds correct to me. Let us know if you have any success. (btw technically we would say the address flag bit is the 9th bit. This can be confusing because you would also say it is bit 8 because we call the first bit: bit 0.)
 

Hi dowdell.i have a small doubt.making the ADDEN bit high does the reciever buffer will load only address bytes & ignore 8 bits data bytes?if i want to load data bytes into rx buffer then immediately i want to make ADDEN=0 after reading address bytes.is this correct.

I hv success with sending bytes induvidually didnt try sending add bytes followed by data bytes.
 
* Master will transmit slave address, make 8th bit high to make this an address byte.
As far as bit number going if I see something like 5th 8th 9th or whatever it's a counting system, so in this case it would be the 9th bit as 0th is not something that makes sense in the English language. In common language 0 isn't really considered a number it's more of a placeholder. Ask 100 people to count to 10, I doubt any of them will start with 0.
 
Coincidently I've been working with addressable UART today and was going to make a post about hot to improve my code. Basically what I've got now works I think (haven't actually tried it with two pics on the same bus) but seems to be working. Each time I want to send a new byte to the pic I have to resend the address. Is that the normal way to do it?

There isn't a lot of information around on 'net about addressable UART, which I'm guessing is because I2C would be the preferrable choice! I was only really doing this as a coding exercise. To address the pic with this code I've been sending the ASCII character 'a' (decimal 127, hex 61).

Code:
	LIST P=16F628A
;
	#include "P16F628A.INC"
;
	__config _BOREN_ON & _CP_OFF & _PWRTE_OFF & _WDT_OFF & _LVP_OFF & _MCLRE_OFF & _INTOSC_OSC_NOCLKOUT
;
	CBLOCK	0x20
		addre				;PIC Address
	ENDC
;
	ORG		0x000
;
		movlw	0x07
		movwf	CMCON		;Turn Comparators Off

		movlw	0x61
		movwf	addre		;Address set at 127
;
; CONFIGURE USART
;
			bsf		STATUS,RP0	;Select Bank 1
;
		movlw	b'00000110'
		movwf	TRISB		;Set bits <2:1> in TRISB	[pg73]
;
		movlw	0x19
		movwf	SPBRG		;9600 baud, 1 stop bit, no parity bit w/ 4MHz Int. Osc.
;	
		movlw	b'00100100'
		movwf	TXSTA		;Configure Tx for Highspeed Asynchrounous comms.

			bcf		STATUS,RP0	;Select Bank 0

		movlw	b'11011001'
		movwf	RCSTA		;Configure 9-bit reception with address enable
;
; MAIN PROGRAM
;
loop	        call	address
		call	receive 
		movwf TXREG                    ;Echo back byte
		bsf	RCSTA,ADEN             ;Re-enable address detection
		goto	loop
;
; ADDRESS SUBROUTINE
;
address	btfss	PIR1,RCIF
		goto	address

		movf	RCREG,W

		subwf addre,W                    ;Subtract addre from W
		btfss	STATUS,Z                   ;If z bit is set then the result was zero. Address match.
		goto	address

		return
;
; Rx SUBROUTINE
;
receive	bcf	RCSTA,ADEN               ;Clear the ADEN bit
		bcf	PIR1,RCIF                   ;Clear RCIF bit

		btfss	PIR1,RCIF                   ;WAit to receive byte
		goto	receive

		movf	RCREG,W                    ;Move RCREG to W
		return

	END
 
Last edited:
Hi Pete the code looks ok.But you can fine tune it more.

When dealing with multiple bytes I'd check Framing Errors & Overrun Error bits as well.Also You don't hang around inside a subroutine while it receives data you can add a timer to expire the receiving loop.

Normally you cannot clear the RCIF bit with bit oriented commands.It will clear when you read the RCREG.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…