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 CCS Technical Support

Setting software UART pins on a 18F4620

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
D-Kens



Joined: 09 May 2005
Posts: 35
Location: Toulouse (France)

View user's profile Send private message MSN Messenger

Setting software UART pins on a 18F4620
PostPosted: Tue Sep 22, 2009 8:41 am     Reply with quote

Hi...

We are currently using an architecture based on a PIC18F4620, with hardware UART on pin C6/C7, and a software UART configured on pin C1/C2.

To add some new features to that prototype, we would like to interface with another RS232 driven device using a dedicated UART. How many software UARTs can I set on this PIC, and what are the available/recommended pins for that purpose ?

I found nothing about that in the datasheet (maybe I didn't look carefully enough). Crying or Very sad

Regards,
Christophe.
Ttelmah
Guest







PostPosted: Tue Sep 22, 2009 2:54 pm     Reply with quote

Data sheet has nothing to do with it. The software UART, is a CCS function, _software_, not 'hardware' (which is what the data sheet covers....).
You can use any pins at all, but with the following limitations:

1) Obviously hardware pin limitations apply, so you can't use a pin that is 'input only' for an output. Similarly signalling level limitations, will be those of the hardware pin.
2) You can only be sending/receiving on any _one_ pin at a time. If you want to receive from two sources, these _must_ do things at different times. While sending, you can't receive (and will miss any data that arrives while you are sending).

This later is the 'killer' for most things. Unless the comms are completely under your control, and 'one thing at a time', the software UART won't help at all.

A search here, will find timer interrupt driven software UARTs (I posted one only a few weeks ago), and these can be modified to support multiple channels, and simultaneous send/receive, but obviously this involves moe and more processor time being involved. Another alternative is to add external hardware UARTs (Maxim, and Phillips both do units, that can be interfaced with relatively few pins).

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 22, 2009 3:06 pm     Reply with quote

You can have several software UARTs and they can go on most i/o pins.
Limitations: You can't put a Tx pin on an input-only pin. An open-drain
pin will require an external pull-up resistor when used as a Tx pin.

But be aware that CCS uses software delay loops to count off the bit
intervals in their software UART library code. This requires that the
full attention of the PIC be concentrated on the Tx or Rx pin, while it's
transmitting or receiving a byte. This means it can't be interrupted.
This also means it's half-duplex. (The hardware UART is full duplex).

One improvement that can be done is to use the INT0 pin (on pin B0)
as the Rx pin, to detect the start bit of an incoming byte, and then have
it go to an #ext_int routine to receive the byte with a getc() statement.

Additonal information:
CCS uses the 3rd type of software UART method, as listed on this page:
http://www.8052.com/faqs.phtml?FAQ=124758


---
Edit:
Ttelmah did his post while I was typing mine in. I'll leave mine up anyway.
Guest








PostPosted: Tue Sep 22, 2009 6:20 pm     Reply with quote

There is a way but you need more hardware.

Using multiple MAX-3100 external SPI uarts might help you if your C3,4,5
pins are free or can be shared.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Sep 22, 2009 6:50 pm     Reply with quote

The MAX-3100 is not easy to interface to in interrupt mode. Personally I like the NXP UART chips better.
D-Kens



Joined: 09 May 2005
Posts: 35
Location: Toulouse (France)

View user's profile Send private message MSN Messenger

PostPosted: Wed Sep 23, 2009 2:18 am     Reply with quote

Ttelmah wrote:
Data sheet has nothing to do with it. The software UART, is a CCS function, _software_, not 'hardware' (which is what the data sheet covers....).

Ouups, I did it again... ! Embarassed Seems I had a blonde moment : you're obviously right. Dunno why I was expecting to find something about that topic in the datasheet.

Ttelmah wrote:
A search here, will find timer interrupt driven software UARTs (I posted one only a few weeks ago)

Lately, I didn't check the forum on a regular basis. I'll search for your code and try to understand/adapt it... Thanks !

PCM Programmer wrote:
This requires that the full attention of the PIC be concentrated on the Tx or Rx pin, while it's transmitting or receiving a byte. This means it can't be interrupted.

Yeah, I'm aware of that problem. As stated in my first post, I'm yet using one software UART for some requests, and I noticed that I couldn't send/receive datas with it while having a timer interrupt enabled. But I guess it's not such a big deal if the PIC is the only master in the system and decides whenever it wants to communicate with its peripheral : I can have it fully dedicated to one COM at a time. It'll be more tricky if the peripherals can send messages at any time... Confused

PCM Programmer wrote:
One improvement that can be done is to use the INT0 pin (on pin B0) as the Rx pin, to detect the start bit of an incoming byte

Sounds like an idea !!! I'm not sure to use that interrupt, but I think I'll suggest that B0 is used as RX pin for one software UART : it'll be up to me then to use (or not) this functionnality, depending on the requirements of my software.

PCM Programmer wrote:
Ttelmah did his post while I was typing mine in. I'll leave mine up anyway.

Well, better read the same twice advice than read nothing at all... Wink And you added some extra informations that weren't in Ttelmah's post.

Ok, thank you both for your answers : guess I'll try to gather a little bit more informations before wiring a first prototype and making tests, but that's yet a god basis for hours and hours of brainstorming. Cool Thanks also to the others for their feedback about using external devices : I'm trying to avoid that solution at the moment, but I'll keep it in mind if the software UART is too limitative.

Regards,
Christophe.
Ttelmah
Guest







PostPosted: Wed Sep 23, 2009 2:58 am     Reply with quote

The 'multiple reply while posting' thing, is very common. I do it with PCM Programmer a lot. Usually have three quarters typed a post, get a phone call, then push 'send', to find that PCM had posted five minutes before me. This time I beat him!...
The timer based code, was about implementing RS232 on a chip that hadn't got a hardware UART.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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