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

Multiplexing RS232 with a pic

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



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

Multiplexing RS232 with a pic
PostPosted: Mon Aug 01, 2011 9:21 pm     Reply with quote

Hi,

It's been awhile since the last time i've logged here on the forum... community is still nice Smile but my skills are now a little bit rusted (have not touched CCS compiler for nearly a year!)

Any idea how i would multiplex a rs232 link?

Example:


Code:

                MASTER (Windows CE ARM, TX-RX)
                     l
                     l

              RJ45 Junction box with a pic (could be 18f2550)
              use rs232 hardware for PIC (this one) to MASTER
              use 8 i/o lines, 2 per slave for RX / TX

               l            l            l           l
               l            l            l           l
               l            l            l           l
           SLAVE         SLAVE         SLAVE      SLAVE
             PIC         PIC           PIC           PIC
          TX-RX         TX-RX         TX-RX         TX-RX



baud rate would be 9600, i think its feasible in software for 4 rs232

With the multiplexer i can send in the packet a magic byte which determine the packet is destined to which slave (yes, like a ethernet switch) so in the slave pic it can listen to anything on the rs232 since packet have been sorted earlier in the multiplexer.

I know about rs485 and all but since a have a box full of pics a good compiler ;).... software is universal! Smile

best regards,
laurent
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: Multiplexing RS232 with a pic
PostPosted: Tue Aug 02, 2011 11:56 pm     Reply with quote

ELCouz wrote:
Hi,

It's been awhile since the last time i've logged here on the forum... community is still nice Smile but my skills are now a little bit rusted (have not touched CCS compiler for nearly a year!)

Any idea how i would multiplex a rs232 link?

Example:


Code:

                MASTER (Windows CE ARM, TX-RX)
                     l
                     l

              RJ45 Junction box with a pic (could be 18f2550)
              use rs232 hardware for PIC (this one) to MASTER
              use 8 i/o lines, 2 per slave for RX / TX

               l            l            l           l
               l            l            l           l
               l            l            l           l
           SLAVE         SLAVE         SLAVE      SLAVE
             PIC         PIC           PIC           PIC
          TX-RX         TX-RX         TX-RX         TX-RX



baud rate would be 9600, i think its feasible in software for 4 rs232

With the multiplexer i can send in the packet a magic byte which determine the packet is destined to which slave (yes, like a ethernet switch) so in the slave pic it can listen to anything on the rs232 since packet have been sorted earlier in the multiplexer.

I know about rs485 and all but since a have a box full of pics a good compiler ;).... software is universal! Smile

best regards,
laurent


If you are sending standard ASCII (not binary) and there is no slave-to-slave communication then the simplest way to do this is have the master add a target identifier to the start of a packet and all slave PICs receive the same message and determine if they need to process it. In this was only the transmit traffic from the slave PICs needs to be multiplexed.

However you can certainly do the TX/RX multiplexing. I have run 1HW and three SW UARTS full duplex at 115200 on a PIC18F series processor running at 40MHz so 1HW UART at any speed and 4 software UARTS at 9600 baud is achievable.

The way I would treat this is to use a single timer for the transmit function running at the bit time. This would be interrupt driven and service all four SW UARTS at the same time.

For the receive but timing I would use a timer running at a multiple of the bit rate, I typically use 3 times, and use this for bit timing.

Each SW UART has a Tx and Rx state machine associated with it and each has its own Rx and TX buffer space allocated with their respective transmit and receive head and tail pointers.

The interrupt driven TX routine drains the transmit buffers, the interrupt Rx routines fill the receive buffers.

The main line code extracts from the respective receive buffers and add to the respective transmit buffers.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Wed Aug 03, 2011 7:39 am     Reply with quote

Thanks Andrew for the reply!

However, I'm now thinking more about rs485 solution since many pics will be in a engine bay.

Nasty EMF and RF are all around especially near spark plugs!

I think TTL level serial communication between pics will give me garbage on the lines.

RS485 is not bulletproof but at least more resistant to interferences.

After digging in my stuff, I've realized that a have a hand full of TI SN65HVD22 also called SuperRS485.

http://focus.ti.com/docs/prod/folders/print/sn65hvd22.html

thank you!
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
dorinm



Joined: 07 Jan 2006
Posts: 38

View user's profile Send private message

PostPosted: Wed Aug 03, 2011 11:39 am     Reply with quote

i think you don't really need any pic-based "multiplexer" Smile, a single max232 with capacitors, 4 diodes and 1 resistor will do the trick ;) ...if you don't figure aout, ask me and i'll show you how.

Regards
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Wed Aug 03, 2011 11:48 am     Reply with quote

Quote:
i think you don't really need any pic-based "multiplexer" Smile, a single max232 with capacitors, 4 diodes and 1 resistor will do the trick ;) ...if you don't figure aout, ask me and i'll show you how.


Multiplexer was to handle packet collisions (ex: two slave transmitting data at the same time on the same line)

If your solution can avoid collisions, I would like to know more about that Very Happy

thanks!
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
dorinm



Joined: 07 Jan 2006
Posts: 38

View user's profile Send private message

PostPosted: Thu Aug 04, 2011 6:09 am     Reply with quote

however you said earlier that you will rely on a 485 network, how will you avoid there packet colision? also , if you think that you will have more than one "slave" transmitting at the same time then i can see no other solution than to use maybe 2 hw uart pic's or 4 pics with single hw uart and then link them together on another highspeed bus like SPI. ..
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Thu Aug 04, 2011 8:39 am     Reply with quote

Quote:
however you said earlier that you will rely on a 485 network, how will you avoid there packet colision?



Quote from RS485.com

Quote:
The master initiates a communications request to a "slave node" by addressing that unit. The hardware detects the start-bit of the transmission and automatically enables (on the fly) the RS485 transmitter. Once a character is sent the hardware reverts back into a receive mode in about 1-2 microseconds (at least with R.E. Smith converters, repeaters, and remote I/O boards).


You also have the ability to control DE and RE pins (Data Enable and Receiver Enable) which you control the mode of the chip either listening , sending or standby.

thanks
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
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