Sending data form non TX/RX lines

Ok. i found myself in one strange situation and i have to find fast way out. The guy that designed my pcb has used tx/rx lines to communicate with one serial device. The problem is that i have to connect one additional device to my pcb but i dont have any rx/tx lines left.

So i was thinking on doing this:

I can take 2 unused MCU lines connect them to max485 and pass the data to max485/USB and then to PC.

Now, how to define this lines as "serial" and do i need something else accept writing some standard serial routines, setting boud rate etc to make this work ?

E.

Reply to
en2
Loading thread data ...

If there's not a UART attached to those lines then you need to bit-bang the serial. This is going to use the processor heavily; the higher the baud rate you want the more it's going to load it down.

What processor are you using? What pins do you have available? There may be some small savings in time if you can connect to a pin for transmit that can interrupt the processor, or even better can be attached to a timer compare pin.

On the receive side you will need to synchronize to the incoming data, then you will need to sample the incoming bits, then you will need to convert from serial to parallel.

On the transmit side you just need to convert from parallel to serial and send.

--
Tim Wescott 
Control system and signal processing consulting 
www.wescottdesign.com
Reply to
Tim Wescott

It's not that hard to do if you have spare timer match/capture ports available. Search around for "software UART". Atmel has an app note over at that I used as the basis of one that I cranked up on an ARM a couple of years ago.

Reply to
Rich Webb

On a sunny day (4 Aug 2013 11:05:18 GMT) it happened Jasen Betts wrote in :

There are a few catches with 'software UART' It largely depends on what you want to do.

If your program flow is simply get serial character[s], process it, and maybe send reply, then there is no need for any interrupts.

loop2: for all bits you want to read a byte (8?) loop1: test if line high, if not loop 1 test if line low (start bit detected), if not loop 1 wait a bit (time) soft delay read pin for first bit, store, shift end for all bits in a byte

// now you have a byte do something with it FAST (or maybe store in buffer) if byte is not end sequence (some indicator) goto loop2 (more bytes)

// now you have all bytes of a data field do your thing with the data

send reply in same way (start bit soft delay (THE SAME DELAY subroutine), maybe stop bits, maybe parity bit) goto to loop2 for more bytes.

There is of course time constrained, but often there is enough time for processing.

The big thing to watch is that it is not sufficient to test for line low = bit present, you need to test for line CHANGE from high to low, see first lines., Modern micros will have port interrupt on edge however, and then you can use that, but now REALLY needed in most cases. Without interrupts things may even be more reliable.

formatting link

But by all means, if your micro has interruptd (available) use them...

Reply to
Jan Panteltje

The MAX485 device requires 3-lines: Txd, RxD, Enable

formatting link
( see page 7 )

Unless you use one pin as serial I/O and one pin to control direction.

Reply to
hamilton

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.