SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By hoffmann
#166135
Hello everybody.
I love to use sparfun items but I am facing a problem.
The most often, I am using some PIC18Fxxx which have 1 or 2 serial line but never more, and I see a lot of cool sensor asking for serial communication (thermal printer, finger recognision, lcd, etc).

How do you do usualy ? Do you use a decoder or something ?
Do you put all your device on the same lines (tx and rx) ?

Thank you a lot !
By waltr
#166136
Are you asking about Async serial as from the PICs' USART?
If so this can not be multi-plexed among different devices easily.
I've never needed more than two asyc serial ports on a PIC and use a Software (bit-banged) serial for the second port.

Or are you asking about SPI or I2C from the PIC's SSP module?
These allow multiple Slave devices on the bus.
By hoffmann
#166224
Hello,
I understood the difference between UART and things like I2C.
Often I see some device wich comunicate with UART (printer, finger scaner, gps, etc) and few on I2C.
My question was more, how with only one or two UART on a PIC deal with several devices (who need uart)...

Thank you !
By skimask
#166230
Software serial (e.g. bit-banged). Done it myself a number of times.
Sure, can only receive one at a time, but it's better than nothing.
Past that, multiplexing using some AND gates and some steering logic might work depending on your situation.
By rmteo1
#166234
All TI TM4C129 microcontrollers have 8 UARTs - also some STM32F4xx have up to 8 UARTs. Some NXP parts with the SGPIO (Serial GPIO) module can be configured to give 20+ UARTs.
By waltr
#166248
hoffmann wrote:Hello,
I understood the difference between UART and things like I2C.
Often I see some device which communicate with UART (printer, finger scaner, gps, etc) and few on I2C.
My question was more, how with only one or two UART on a PIC deal with several devices (who need uart)...

Thank you !
Ok. You did not specify which type of serial so I how to ask.
The UART/USART has two serial modes (synchronous and asynchronous), SPI and I2C are also serial.

I use bit-banged Async seial when I need additional ports. Easy to do if send only and a little more involved for receiving.
Microchip has several App Notes on doing bit-banged Async serial and one that demonstrates how to do a RTOS that sends four async and receives one all at the same time. Check App Notes: AN510, AN555, AN593 then AN585.

Another method would be to use an external MUX to route the PIC's UART to/from the different devices.
By skimask
#166252
I used that app note a few years ago as a base for an 8 port bit-banged serial port, except mine went both ways, async. PIC18F26K22, bulk of it written in PicBasicPro, core/time-critical stuff done in straight assembly, totally interrupt driven, lots of flags, 7x oversampling, and so on... IIRC, I only got 4800 baud out of it reliably. Might've got more speed if I'd have put more work into it, or possibly lightened up on the rest of the stuff the PIC was doing at the same time, but 4800 was all I needed.
Searching for my code now...apparently it's buried...in my old XP machine that hasn't been turned on in 2+ years...(ready for some Windows update fun???)