CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

[SOLVED] PIC18F04Q40 UART problem
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
alan



Joined: 12 Nov 2012
Posts: 349
Location: South Africa

View user's profile Send private message

PostPosted: Fri Mar 18, 2022 3:33 am     Reply with quote

From the datasheet
Quote:
Asynchronous Address Mode
A special Address Detection mode is available for use when multiple receivers share the same transmission line, as
seen in RS-485 systems.
When Asynchronous Address mode is enabled, all data is transmitted and received as 9-bit characters. The 9th bit
determines whether the character is address or data. When the 9th bit is set, the eight Least Significant bits are
the address. When the 9th bit is clear, the Least Significant bits are data. In either case, the 9th bit is stored in
PERIF when the byte is written to the receive FIFO. When PERIE is also set, the RXIF will be suppressed, thereby
suspending DMA transfers allowing software to process the received address.
An address character will enable all receivers that match the address and disable all other receivers. Once a receiver
is enabled, all non-address characters will be received until an address character that does not match is received.


Also
Quote:
Addresses are sent by writing to the UxP1L register. This transmits the written byte with the 9th bit set, which
indicates that the byte is an address.

So this chip fully support 9-bit mode.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Mar 18, 2022 5:25 am     Reply with quote

There are 2 different 9 bit 'modes', at least for old guys like me.

The first, that this PIC does support, is where the 9th bit is used as a 'flag' to show whether the 8 data bits are to be used as an address or as data. Motorola sold the MC14469 Addressable UART, decades ago. A 40 pin device that PICs now mimic.AN806 is worth reading BTW.

The second mode, is a true 9 bit DATA mode, where the serial stream consists of a start bit, NINE data bits, optional parity bit and the stop bit. Historically discrete UARTs could be configured for 5,6,7 or 8 data bits as well as 1, 1.5 or 2 stop bits, as well as even,odd,or no parity. If you had a bipolar(+-) 8 bit ADC, having a 9 bit UART meant you could send the ADC value in a single transmission where 8 bits were the result and the 9th bit the sign (+ or -).
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri Mar 18, 2022 10:05 am     Reply with quote

Spot on Jay.

The point is this chip _does not_ support 9 bit data. It only supports the
address mode.
If you want 9bit data mode, this chip won't do it.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Mar 19, 2022 5:38 am     Reply with quote

One possible, maybe, option is to use a software UART.

I've done that for decades with my 22 bit serial interface needs.....

It all depends on what is on the 'other end' of the serial link.....
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sun Mar 20, 2022 10:37 am     Reply with quote

With a bit of 'sneakiness', this could be a good solution.
Use a software UART for TX, and a hardware one for RX. Enable 8 bits
with parity on this.
Then simply read the 8bits plus the UART parity bit to build the 9bits.
alan



Joined: 12 Nov 2012
Posts: 349
Location: South Africa

View user's profile Send private message

PostPosted: Tue Jun 28, 2022 1:24 pm     Reply with quote

Just an update on this old post.

The UART1 on this PIC does support full 9 bit operation, but you have to set it up manually as the #use RS232 option does not yet support it and you have to set it up manually.

The U1ERR contains a bit stating that an address have been received and thus reading the RX register contents should be treated as that an address has been received.

To send an address you put the byte in U1P1 and it get send with the 9th bit set.

Regards
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Tue Jun 28, 2022 10:29 pm     Reply with quote

Except that isn't a standard 9bit mode.
The point is it only handles '9bit' as an address.
So as I said earlier, you can do this, but as you describe, you are having to
cheat, detect and handle the address flag to get 9bit operation.
Not standard 9bit data operation.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jun 29, 2022 5:20 am     Reply with quote

Curious, I'm wondering who actually has peripherals that have NINE data bits ? It seems odd (no pun), that anything would have 9 bits. PICs ADC can be 8 or 10, uses 2 bytes, no big deal. I used 16bit ADCs in the past, never anything with odd number of bits...well, OK, Teletypes did ...7 bit BUT back then NO PICs, heck NO UARTS ! A board full of 7400 series chips WAS the UART.
I do have some Motorola Addressable UARTS here (145469 ?), they are 8 bit data.
Still, be nice to know what's on the 'other end' of the wire.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Jun 29, 2022 8:09 am     Reply with quote

The commonest use for 9bits, _is_ for addressing. This is why this particular
PIC offers it like this. So you have a byte with the 9th bit set as an
'indicator' that this is an address byte.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group