Go Down

Topic: Inverted serial on Arduino Due (Read 5265 times) previous topic - next topic

veneridesign

Hi everyone,
I have a big problem with a serial display that need a Inverted TTL to comunicate (bit start=1, data inverted, bit stop=0),
so I Know that not exist any serial software library on Arduino DUE and in my project I can't use a external PNP to invert the signal..
Any idea for a software solution?
Can I create a wire jumper that "Digital.read" the Tx signal , invert it and create a digital output ? or simply a register option who "invert" the serial port signal?

Thank You for any help.....

Luca

AdderD

You can make the serial port run in inverted mode. For a previous person I posted the following snippet as a way to do what they wanted:
Code: [Select]

#include "USARTClass.h"

Usart *_pUsart;

void setup() {
  // put your setup code here, to run once:

  _pUsart = USART0; //USART0 is Serial1, change this for other serial ports
  _pUsart->US_MR = US_MR_USART_MODE_RS485 | US_MR_USCLKS_MCK | US_MR_CHRL_8_BIT | US_MR_PAR_EVEN  |
                   US_MR_NBSTOP_1_BIT | US_MR_CHMODE_NORMAL;
 
}
void loop() {
  // put your main code here, to run repeatedly:
 
}


You can do the same thing. You need to set inverted mode in your mode call and you probably don't want many of the other options that that user needed. But, you could do this:

Code: [Select]

  _pUsart->US_MR = US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_8_BIT | US_MR_PAR_NO  |
                   US_MR_NBSTOP_1_BIT | US_MR_CHMODE_NORMAL | US_MR_INVDATA;


All of these mode setting definitions are found in arduino/sam/system/CMSIS/Device/ATMEL/sam3xa/include/component/component_usart.h

And, remember, all that code was setting the mode for Serial1. If you aren't using Serial1 then you will need to that _pUsart = line. Serial is NOT a USART but rather a UART and the mode definitions are probably different. You should still be able to do the same basic thing but you'll have to look up the mode bits.

veneridesign

Tank you for all this informations! you have been very accurate and comprehensive.
I try now to put them into practice

Luca

veneridesign

Hello,
last question about this topic.., trying to understand better the INVDATA function I read the manual but I can't understand very well the meanig of this... :~

"• INVDATA: INverted Data
0: The data field transmitted on TXD line is the same as the one written in US_THR register or the content read in US_RHR
is the same as RXD line. Normal mode of operation.
1: The data field transmitted on TXD line is inverted (voltage polarity only) compared to the value written on US_THR register
or the content read in US_RHR is inverted compared to what is received on RXD line (or ISO7816 IO line). Inverted
Mode of operation, useful for contactless card application. To be used with configuration bit MSBF."
.......

In my application I need that even the bit start and stop are inverted but I think INVDATA works only on data field...
Any solutions? I'm wrong?
Thank  you again

Luca

Grumpy_Mike

Quote
Any solutions?

Well I would say only hardware. Why is there not enough space to put a transistor in?

veneridesign

Only for a saving reason, a transistor means a new external PCB = a lot of money in large number..And  a matter of elegance of design, if one thing can be simulated, why do  it  in real world ?
I can't belive that ARDUINO DUE can't send a  full "inverted serial signal"

Luca

MarkT

#6
Jan 20, 2014, 01:30 am Last Edit: Jan 20, 2014, 01:36 am by MarkT Reason: 1
A quick (and untested) thought - perhaps the PIO devices have an invert register?

[ then I looked and it seems not...  there is support for open-drain, probably what I
was half-remembering ]

Anyway this option might be fruitful still:
Quote
Can I create a wire jumper that "Digital.read" the Tx signal , invert it and create a digital output ? or simply a register option who "invert" the serial port signal?


Connect to a spare pin and use that to trigger an interrupt driving yet-another-pin...  Not
great for high speed though.  I don't think there's a way to patch-panel the pins in hardware
(might be useful for this sort of problem and for generating antiphase signal pairs).
[ I DO NOT respond to personal messages, I WILL delete them unread, use the forum please ]

graynomad

Quote
I can't belive that ARDUINO DUE can't send a  full "inverted serial signal"

I've never seen a UART that did to this, although someone pointed one out the other day.

_______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Grumpy_Mike

The other way is to hack the software serial and do it like that. I also have never come across a processor with an inverted UART capability, so you are asking for something very unusual.

veneridesign

#9
Jan 20, 2014, 11:52 am Last Edit: Jan 20, 2014, 11:53 am by veneridesign Reason: 1
To be honest the "invert" option in Serial software is born because the world is full of "ttl inverted" devices ... So if you have a little experience... is not so unusual....
By the way thnks

Grumpy_Mike

Quote
the world is full of "ttl inverted" devices ... So if you have a little experience... is not so unusual....

Yes but I have been playing this game for over 40 years and I have never come across them.
I did design an RFID reader where it was required that the signals from a decoder was inverted serial but that's about it. I also play in the comms space where you would expect to come across them.
Guess I just lead a sheltered life.

The thing is that TTL logic floats high and that is a natural for a mark on a serial line, mark being the un-driven state of a line.

Go Up