View previous topic :: View next topic |
Author |
Message |
ercarlitosg
Joined: 08 Sep 2014 Posts: 20
|
Creating software uart at runtime |
Posted: Fri Jul 03, 2015 5:27 am |
|
|
Hello,
I need to manage a lot of serial port with a 18F87K22. I know that it has 2 hardware uart and up to four software uarts. But I need about 24 serial port. I haven't found how to change the uart at runtime, for example, I have one at pins RC4 and RC5 and at some time I want change to RB4 and RB5. Is this possible in CCS?
Thanks |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Fri Jul 03, 2015 5:41 am |
|
|
24 serial ports ? That's 48 pins...OK, it _can_ be done using that PIC BUT what speed are the serial ports? Do you need both TX and RX for every port?
All the software' ports must be 'polled', and that is really,really 'messy' . While the PIC is servicing one software port it WILL miss data on one of the other 23.
Seriously you need to rethink the plan. EVERY serial port should be a hardware UART, so you can use smaller PICs( <$1) for that part,then say use I2C or SPI to interface to the big PIC to carry on with the 'main' program. incoming data MUST be buffered ( X24 !!).
Even then it's not an easy task but broken into manageable sections could be done.Obviously start with say 2 ports, then 4 then 8..... Hardware layout could be critical,especialy for the high speed interfaces.
Would need to know a lot more details. baudrate, serial interface(real RS232 or just TTL),size of incoming data, overall purpose, etc.
The more you tell us the better we can help.
Jay |
|
|
ercarlitosg
Joined: 08 Sep 2014 Posts: 20
|
|
Posted: Fri Jul 03, 2015 6:08 am |
|
|
temtronic wrote: | 24 serial ports ? That's 48 pins...OK, it _can_ be done using that PIC BUT what speed are the serial ports? Do you need both TX and RX for every port?
All the software' ports must be 'polled', and that is really,really 'messy' . While the PIC is servicing one software port it WILL miss data on one of the other 23.
Seriously you need to rethink the plan. EVERY serial port should be a hardware UART, so you can use smaller PICs( <$1) for that part,then say use I2C or SPI to interface to the big PIC to carry on with the 'main' program. incoming data MUST be buffered ( X24 !!).
Even then it's not an easy task but broken into manageable sections could be done.Obviously start with say 2 ports, then 4 then 8..... Hardware layout could be critical,especialy for the high speed interfaces.
Would need to know a lot more details. baudrate, serial interface(real RS232 or just TTL),size of incoming data, overall purpose, etc.
The more you tell us the better we can help.
Jay |
I can't use SPI or I2C because of the range between every terminal connected to the master pic (this). It needs to be RX and TX and there aren't going to transmit at the same time the baudrate doesn't matter, it could be slow, because the maximum data that be transmitted by each pic and wouldn't pass the two characters. Also I need the one of the harware uart to connect to the the computer at a baudrate of 9600 or 19200, but also are only transmitting about 6 characters |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1353
|
|
Posted: Fri Jul 03, 2015 11:31 am |
|
|
If they aren't going to be transmitting at the same time, how about using a mux + demux and a single hardware UART? |
|
|
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
|
|
guy
Joined: 21 Oct 2005 Posts: 297
|
|
Posted: Sat Jul 04, 2015 3:17 am |
|
|
you could divide the task into waiting to find which channel is transmitting data and then 'focus' on that channel.
Waiting and polling is easy since the PIC is quite fast. Scan each port with input_x() to see if it's changed from 0xFF.
Once you know which port and then which channel is sending data you can either use a mux such as Quote: | CD4067: 16 Channel Analog Multiplexer/Demultiplexer | and channel it to a single HW uart or create a software UART that can handle the input/output pin as a variable.
TIP: since you use long cables there might be occasional spikes (noise) which would trigger the scanning mechanism. You can easily add some code to filter it out before deciding that there is a real transmission occurring. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Sat Jul 04, 2015 4:54 am |
|
|
As a separate comment, consider RS485....
Handles distance better than RS232, and supports multiple devices on one pair of cables, so a single UART could handle all the devices. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Sat Jul 04, 2015 7:15 am |
|
|
RS485 would be a nice solution(easy to implement and code) but... I think the OP already has 24 RS232 'terminals' he needs to communicate with
hmmm...
he could add simple RS232<>RS485 'dongles' at each terminal. That will allow RS485 and a simple, cost effective solution that's easy to code AND be reliable.
The more info he supplies the more solutions we can offer.
Jay |
|
|
mbradley
Joined: 11 Jul 2009 Posts: 118 Location: California, USA
|
|
Posted: Sun Jul 05, 2015 12:16 am |
|
|
This sounds like a CNC type of requirement, not sure if this is off topic or not, but I took a Serial Terminal network box, ie: one ethernet, 32 serial ports.
And I used a serial to lan emulator, this any pc on the network can send serial data to any serial port on the box. _________________ Michael Bradley
www.mculabs.com
Open Drivers and Projects |
|
|
ercarlitosg
Joined: 08 Sep 2014 Posts: 20
|
|
Posted: Sun Jul 05, 2015 3:04 pm |
|
|
Thanks for all your answers. Sorry, I didn't mention that I was going to use rs232 to rs485 converter (which I actually don't remember the model, I will update when I have it). But also, I talked to a relative of mine who codes in PBP (I don't like it, I prefer a lot CCS) that he can reassign virtual serial ports at runtime in PBP, so I was very surprised that i can't do that on CCS.
I think I will give a try to the mux.
Also, if this is helpful the terminals are pic16f877a.
Thanks |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Sun Jul 05, 2015 3:44 pm |
|
|
CCS C will allow you 24 serial ports, just lookup 'streams' in the manual for the correct syntax.
Even back in V2.450 CCSs allowed multiple serial ports though each was software driven. It was the main reason I bought it, as well as a zillion good code examples and friendly staff !
Jay |
|
|
ercarlitosg
Joined: 08 Sep 2014 Posts: 20
|
|
Posted: Wed Jul 29, 2015 4:39 am |
|
|
Thanks for your answers. I finally decided to re-think the project and I will use an enc28j60 and ethernet switches. This will make the installation cost of the network cheaper than installing a new private network of the project terminals where they will go. |
|
|
|