SerialX.transmitterEnable(pin)

Status
Not open for further replies.

profor

Active member
Hello,

i am working on a project, where i will be able (using teensy) to "talk" to HART enabled transmitters on 4-20mA loop.
HART protocol is known to me, so there is no problem understanding the messages.

I am using old HART modem Endress+Hauser Commubox FXA191 where i put USB to UART converter using CP2102 chip.
The HART modem is set to 1200 / Odd parity / 1 stop bit. The modem requires the RTS to start modulating the HART message to the loop.
The RTS is active LOW.

Now i put Teensy between the CP2102 USB converter and the Commubox.

CP2102 is connected to Serial3
HART modem is connected to Serial2

I would like to use Serial2.transmitterEnable(pin) to "simulate" RTS for the HART modem, but the pin goes HIGH during transmission. My HART modem requires the RTS to be LOW during transmission.

Is it possible to change the "polarity" of the transmitterEnable(pin) somehow? Or should i use transistor to change the polarity (i would like not to)?

transmitterEnable.png

Please note, that the CP2102 RTS is on channel 4 of analyser.
Channel 5 is my transmitterEnable pin.

Thank You
Dusan

Code:
#define RTSout            2
#define USB               Serial3
#define commubox          Serial2

void setup() {

  pinMode(heartbeat_led, OUTPUT);
  pinMode(backlight,  OUTPUT);
  pinMode(psuMosfet,  OUTPUT);
  pinMode(relay,  OUTPUT);
  pinMode(buttons,  INPUT);
  pinMode(led1A,  OUTPUT);
  pinMode(led1K,  OUTPUT);
  pinMode(led2A,  OUTPUT);
  pinMode(led2K,  OUTPUT);
  pinMode(RTSin,  INPUT_PULLUP);
//  pinMode(RTSout, OUTPUT);
//  digitalWrite(RTSout,  LOW);

  USB.begin(1200, SERIAL_8O1);
  commubox.begin(1200, SERIAL_8O1);
  commubox.transmitterEnable(RTSout);
//  commubox.attachRts(RTSout);
  
  lcd.init ();
  lcd.clear ();  
  lcd.setContrast(15);  
  ltc.init(LTC4151::L, LTC4151::L);
  delay(1000);

  
}

void loop() {

  serialComm();

        
}

void  serialComm()  {

  if  (USB.available()) {
      int inByte = USB.read();
      commubox.write(inByte);
  } 

  if (commubox.available()) {
    int inByte = commubox.read();
    USB.write(inByte);
  }  
}
 
Additionally, i would like to ask, if it happened to some of You, that i2c influences (hangs) the uart communication?
Please look at tha attachment.

From my observations, shorter messages does nothing to the serial port (in this case Serial1), but when i write to display (every 250ms) it sometimes hangs the serial communication.
Channel 5 is the transmitterEnable pin which is infulenced too.
Channel 4 is the RTS from CP2102 USB converter, as described before.
Channel 0 is what comes from CP2102 to Teensy (Serial3)
Channel 2 is what goes out from Teensy (Serial1)



i2c_and_uart.png
 
I would like to use Serial2.transmitterEnable(pin) to "simulate" RTS for the HART modem, but the pin goes HIGH during transmission. My HART modem requires the RTS to be LOW during transmission.

Is it possible to change the "polarity" of the transmitterEnable(pin) somehow? Or should i use transistor to change the polarity (i would like not to)?

Yes, you can edit the code in serial2.c. Look for transmit_assert() and transmit_deassert().

https://github.com/PaulStoffregen/cores/blob/master/teensy3/serial2.c#L62

Just change the 1 to a 0 and vise versa.

You'll also have to edit the startup code. Look for the digitalWrite that sets the initial state.

https://github.com/PaulStoffregen/cores/blob/master/teensy3/serial2.c#L198
 
Additionally, i would like to ask, if it happened to some of You, that i2c influences (hangs) the uart communication?
Please look at tha attachment.
....
Channel 5 is the transmitterEnable pin which is infulenced too.

Looks like it's doing exactly what it should. transmitterEnable is high when data is transmitting, and automatically goes low shortly after the end the stop bit which isn't immediately followed by another start bit.

I can't see your code, but it seems very likely its got a design which doesn't keep the serial port continuously sending. Using transmitterEnable is supposed to automatically turn off the transmitter when data isn't transmitting.
 
Status
Not open for further replies.
Back
Top