Hardware UART 9bit Single Line/Half Duplex

Hello,

for a project I need to read serial data with the following value: Communication speed 9600-9800 Baud Number of data bits 9 Number of stop bits 2 ODD parity

Reading works for me with an altered hardware_serial library I found in this forum. However, the reading an transmission needs to be through one wire in half duplex mode. Both pins (rx/tx) need to be connected through a resistor, but I cannot get it to work on the Arduino Mega and Arduino Leonardo.

Reading works but as soon as I plug in the resistor no further data is read and transmission was not successfull either.

Janef

Hello,

it seems that the Pins for TX and RX have pull up resistors enabled if used for serial connection. Is far as I understand, this can negatively affect the ability to transmit via a single wire.

How can I disable the resistors for the Sirial2 on the Arduino Mega 2560?

Thanks

it seems that the Pins for TX and RX have pull up resistors enabled if used for serial connection.

I can't see them on my schematic of the Mega 2560.

Even if it had why do you thing this?

Is far as I understand, this can negatively affect the ability to transmit via a single wire.

In fact what does that even mean?

The pull-up resistors are within the ATmega2560 (as all pull-up resistors are). For pins in regular mode the resistor is deactivated and allows the pin to be in tri-state. If you use, for a regular pin, the pin mode "INPUT_PULLUP" pinMode() the resistor is active and the value of the pin is HIGH and input defaults to logic 1.

From my observations, but I might be wrong, the same happens for the RX Pin for a serial Connection. For normal usage this is absolutely fine. If you need one wire connection for a half-duplex mode boths pins have to be connected: http://www.jetimodel.com/en/show-file/26/

If you do this with a regular tri-state pin, the connection to the device can pull the receiving side down or up. If TX is used and set to highor low it pulls the connection to HIGH or LOW and with it the RX pin (which is not a problem since you clear the echo from the buffer after write). If writing is complete, the TX is set to tristate and does not affect the line.

But if the RX is pulled up (or down) if not needed it will also pull up the whole Line and does not allow for a transmission.

This is at least my understanding and the reason why I would like to disable the pull up resistors.

They are not pulled up in the '2560 - they appear to be high as a result of being connected to the USB/Serial adapter chip thru 1K resistors. See RN4A and RN4B on the Mega R3 schematic at the lower left. I'm pretty sure if you look at Serial.h or Serial.cpp, whatever file is called out by Serial.begin(), you will not find the pullups enabled.

Thank your for your Reply,

to my understanding the quotet resistors are pull up resistors for the ATMEGA16U2(USB & Programmer) serial connection. Could you please explain if and how they affect the TX/RX Pins on the ATMEGA2560 (Controller)?

Thx

They are 1K resistors, thus requiring whatever drives the pins to have ~5mA of drive capability to pull them low. Mega2560 has 20mA output capabilty, so is not a problem. If USB is not connected and the Mega2560 is communicating with an external device, that device must be able to pull low (sink) ~5mA to drive a low input. (low being <= ~1.5V, 0.3 x Vcc) while the high level will help with a high signal.

The pull-up resistors are within the ATmega2560 (as all pull-up resistors are)

All pull up resistors are not internal. Take for example the pull up resistors on the I2C bus. The internal ones are too weak and so on the Mega there external ones.

You asked:-

How can I disable the resistors for the Sirial2 on the Arduino Mega 2560?

There are no pullups for Serial2.

Now you appear to have changed your mind:-

to my understanding the quotet resistors are pull up resistors for the ATMEGA16U2(USB & Programmer) serial connection.

Those are RN4A and RN4B - they are series resistors they are not pull up resistors.

to my understanding the quotet resistors are pull up resistors for the ATMEGA16U2(USB & Programmer)

Your understanding is wrong.

Sorry, I am slow today and still can't follow. Spend to many hours yesterday. Thx for your patiance.

Setup is a connection of a Jeti device to the TX2 and RX2 Pin on the Arduino Mega 2560. Since the device uses half-duplex on a one line transmission, both pins are connected via 2.4k Resistor while the line is connected to the TX pin (www.jetimodel.com/en/show-file/26/). Even during sending the receiving pin is high.

CrossRoads: They are not pulled up in the '2560 - they appear to be high as a result of being connected to the USB/Serial adapter chip thru 1K resistors. See RN4A and RN4B on the Mega R3 schematic at the lower left.

Ok, I found them and missinterpreted them as pull-ups.

Grumpy_Mike: Those are RN4A and RN4B - they are series resistors they are not pull up resistors.]Grumpy_Mike: Those are RN4A and RN4B - they are series resistors they are not pull up resistors.

But I can not understand how they affect the TX2 and RX2 pin.

How does

Grumpy_Mike: All pull up resistors are not internal.

and

http://arduino.cc/de/Main/ArduinoBoardMega: Each pin can provide or receive a maximum of 40 mA and has an internal pull-up resistor (disconnected by default) of 20-50 kOhms

work together?

There are no pullups for Serial2.

ok, understood. Is that true for all TX and RX Pins and also others? I misinterpred the documentation as far as the the internal resistor can be activated for each pin.

I'm pretty sure if you look at Serial.h or Serial.cpp, whatever file is called out by Serial.begin(), you will not find the pullups enabled.

Now I found the corresponding section in the datasheet (example is for the wrong pin, but the others work as well)

• TXD – Port D, Bit 1 TXD, Transmit Data (Data output pin for the USART). When the USART Transmitter is enabled, this pin is configured as an output regardless of the value of DDD1. • RXD – Port D, Bit 0 RXD, Receive Data (Data input pin for the USART). When the USART Receiver is enabled this pin is configured as an input regardless of the value of DDD0. When the USART forces this pin to be an input, the pull-up can still be controlled by the PORTD0 bit.

Thank you for your replies

Please draw a diagram of the circuit you want to use for this. What kind of device are you communicating with? How do you determine if you have to listen or send at any given moment?

Both pins (rx/tx) need to be connected through a resistor, but I cannot get it to work on the Arduino Mega and Arduino Leonardo.

Depending on the circuit on the other side of the communication a resistor is probably not enough.

Maybe a modified SoftwareSerial class better fits your need because there you don't need external circuitry and you can just change the pinMode() depending on if you're sending or receiving.

How does Quote Grumpy_Mike: All pull up resistors are not internal. and Quote http://arduino.cc/de/Main/ArduinoBoardMega: Each pin can provide or receive a maximum of 40 mA and has an internal pull-up resistor (disconnected by default) of 20-50 kOhms work together?

Very simply. Pull up resistors are for inputs. When a pin is providing a current it is an output.

But I can not understand how they affect the TX2 and RX2 pin.

They don't I have been telling you that from the start.

What is your exact problem? If you want to use that protocol you posted then go ahead and wire it up like it says. Note that by default you will not be able to achieve the data format it requires, that will take some looking into.

Setup is a connection of a Jeti device to the TX2 and RX2 Pin on the Arduino Mega 2560. Since the device uses half-duplex on a one line transmission, both pins are connected via 2.4k Resistor while the line is connected to the TX pin (www.jetimodel.com/en/show-file/26/). Even during sending the receiving pin is high.

Easiest way is to connect Tx thru a buffer like 74HC125, and control its output enable. When TX2 is to transmit, enable the buffer; when done transmitting, disable the buffer so the other device can transmit.

Before you get all hung up on internal or external pull-ups you first have to deal with the issue of building a half-duplex com link with typical a microcontroller serial UART com that fundamentally don't support half-duplex electrically (two separate pins Vs a single bidirectional pin). So show us your proposed electrical design between the arduino tx and rec pins and the external serial device. It can be made to work given proper external components, wiring, and software, but again we would have to see what you have to deal with.

This is not unlike people using TTL serial links to RS-485 type converters where there needs to be an additional output pin under software control to tell the converter to flip between transmit mode and receive mode at both ends of the com link.

Thank you.

After setting the the RX Pin again to INPUT after begin(I know it shouldn't have changed a thing) it worked.

I don't have a problem with the data format (I modified the hardware_serial to work with 9bit) at least none I can see. The protocol itself is very easy to implement but thanks for your suggestions.

The devices continiously sends data (with a control sequence to signal the end), then waits 20ms for the controller to answer with a message but doesn't care if no response is received. I work with the messages, wait for the end, transmit the data via the hardware serial and during that I receive the message also on the RX. After sending I discard the incoming buffer (because it only contains the data I have send) and begin to listen.

The only problem, eventhough I learned that I couldn't have been the problem, was setting the INPUT for the RX pin manually.

Thanks for your help, maybe this can save someone attaching a JetiBox to a Arduino some time.

Very simply. Pull up resistors are for inputs.

RX is an input, at least in my setup :)

RX is an input, at least in my setup smiley

Are you being deliberately stupid?

You know what pisses people off here is cross posters who start another thread when all the relevant information was in the previous thread. You just waste people's time going through the process of describing what you are doing again.

Topics merged. Don't start another one.

Today I was poking around in the ATMEGA datasheet and saw:

20.6.3 Transmitter Flags and Interrupts The TXCn Flag is useful in half-duplex communication interfaces (like the RS-485 standard), where a transmitting application must enter receive mode and free the communication bus immediately after completing the transmission.

However, the HardwareSerial.h implementation in Arduino jams TXC0 on between Serial.begin() and Serial.end(). It would require some surgery to get it to do half-duplex.

pix