serial 9-bit on the t3

Status
Not open for further replies.
I'm working to integrate Nick's 9 bit changes into the official code. Since it doubles the amount of memory, I'm inclined to have it disabled by default, but with a #define that can be uncommented by editing the code.

I'm also looking into supporting Serial.begin(baud, format) that was introduced in recent versions of Arduino. Formats like 8N2 & 8E1 actually use the 9 bit mode.

If anyone is currently using this 9 bit stuff, now would be a great time to speak up with any feedback?

One question I have is regarding the Arduino API. Is Serial1.write9bit() really the best way? Would a function that sets or clears the 9th bit work better? Or should the function cause the next byte with Serial.print() or Serial.write() to have its 9th bit set, and then all others revert to zero? My understanding is these 9 bit protocols are used for marking the first byte (a destination address) of a message, so a Serial.ninthBitOnNextWrite() style function might make more sense?
 
To use 9 bits, you'll have to uncomment #define SERIAL_9BIT_SUPPORT in HardwareSerial.h.

Here's a quick test program I used today while watching on an oscilloscope.

Code:
void setup() {
  Serial1.begin(100000, SERIAL_9E1);
  Serial2.begin(100000, SERIAL_8N1);
  Serial3.begin(100000, SERIAL_9N1);
}

unsigned int n=0;

void loop() {
  Serial1.write(n & 15);
  Serial1.write(0);
  Serial2.write(n & 15);
  Serial2.write(0);
  Serial3.write(n & 15);
  Serial3.write(0);
  n++;
  delayMicroseconds(1200);
}
 
Well it took a while, but today we finally adapted a 9-bit fix we made after I asked the initial question in this thread but before the library was updated by Paul to use Paul's 9-bit option and it works beautifully.
Thank you again for adding this!
David
 
I had a super similar situation to PaulW except with different ports. I'm using a Teensy3.1. Serial3 didn't work for me but Serial2 worked great.

I initially had Seatalk data coming in on Serial3. All the data was coming in correctly except for the 9th bit (I could see the message content just fine, but would never see the 9th bit set). I pulled out the oscilloscope and everything in the waveform looked fine --the 9th bit was definitely set in the waveform. Then I tried a loopback test (connecting TX directly to RX) and it mostly worked. It was a little unpredictable but usually the first handful of times I'd transmit it would drop the 9th bit. Then at some point it'd pick up the 9th bit. Then after that it seemed to be really consistent at reading the 9th bit. Very strange.

I switched to Serial3 and everything works perfectly. Similar to PaulW, I didn't change anything else in the hardware, just the pin that the Seatalk data was hooked up to. I'm super relieved it's working now but baffled as to why it didn't work in the first place.
 
Status
Not open for further replies.
Back
Top