RS232 Inverse Polarity

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Raph
Posts: 6
Joined: Wed Dec 07, 2011 11:38 am
Has thanked: 3 times

RS232 Inverse Polarity

Post by Raph »

Hi guys,

I've searched for a way to set up flowcode (V5) to inverse the communication signal of the RS232, but didn't find a solution.

I'm using the software RS232 on a PIC18F2520 @ 2400bps, Tx on RC0 (pin11) and Rx on RC1 (pin12).

So I was wondering if anyone know how to set flowcode (or in C so i can add a C block) to have an inverted RS232 signal.

Have a nice day
Keep coding ;)

Raph

EDIT :
I've found that I apparently need to modify the BAUDCON Register, especially the bit 4 (TXCKP, set it to "1" to inverse polarity). I've look in the C code generated by flowcode and the settings but I didn't find anything regarding this bit or register. Anyone know how can I do this in flowcode (or in a C block) ?

User avatar
DavidA
Matrix Staff
Posts: 1076
Joined: Fri Apr 23, 2010 2:18 pm
Location: Matrix Multimedia Ltd
Has thanked: 58 times
Been thanked: 258 times
Contact:

Re: RS232 Inverse Polarity

Post by DavidA »

Hi Raph,

While im not sure how to do this myself, I would imagine you might be able to customise the C-code behind the component, to do this right-click on the component in the panel and select "Custom Code".

User avatar
Steve
Matrix Staff
Posts: 3433
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Re: RS232 Inverse Polarity

Post by Steve »

I've had a quick look at the datasheet and bit 4 of that register is the "Synchronous Clock Polarity Select bit". I don't think this does what you are asking. You may need to invert the signals in hardware.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 Inverse Polarity

Post by Benj »

Hello,

If you are connecting the microcontroller's UART to a RS232 bus then a logic converter such as a MAX232 will automatically inverse the signals for you as well as convert the voltage levels to +/-12V.

Raph
Posts: 6
Joined: Wed Dec 07, 2011 11:38 am
Has thanked: 3 times

Re: RS232 Inverse Polarity

Post by Raph »

Hi,

Thanks for all your answers.
Benj wrote: If you are connecting the microcontroller's UART to a RS232 bus then a logic converter such as a MAX232 will automatically inverse the signals for you as well as convert the voltage levels to +/-12V.
I use a MAX232 with the hardware UART (to a PC) and it works perfectly, but with the software RS232 I don't need to convert from 5V to 12V so I was wondering if I could inverse the signal directly in the PIC (I know it's possible with the BASIC Stamp).
DavidA wrote: While im not sure how to do this myself, I would imagine you might be able to customise the C-code behind the component, to do this right-click on the component in the panel and select "Custom Code".
I think I'll try to modify the Custom Code and see if I can acheive my goal that way (I ll post here the solution if it works) otherwise I add a MAX232 to do the job in hardware.

Thanks to all of you for your answers and your time

Raph

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 Inverse Polarity

Post by Benj »

Hello Raph,

If your just using a serial signal chip to chip then you shouldn't have to manually inverse the polarity unless the other device is specifically expecting the inverse polarity.

Raph
Posts: 6
Joined: Wed Dec 07, 2011 11:38 am
Has thanked: 3 times

Re: RS232 Inverse Polarity

Post by Raph »

Hello Benj,

That's exactly what the other device want, inverted polarity. I know because I can comunicate with it nicely using an inverted polarity RS232 signal (with a BASIC Stamp). But I would love to move on and use a PIC which is much more faster and with more memory.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 Inverse Polarity

Post by Benj »

Hello,

The easy way would be to use a logic chip like a 74LS04 inverter to switch the polarity of the signal. This would then work for both the send and receive without having to modify any code.

The hard way would be to dig down into the Flowcode software UART code and flip the polarity of all the I/O functionality.

What you require is not a standard recognised method for asynchronous serial data and this is why this mode of operation is not supported directly in Flowcode or on the UART peripherals on the PICs. Seems strange that BasicStamp have adopted this approach.

Post Reply