9 bit Software / Hardware Serial

Hello guys,

i am looking to read / write a serial data protocol with the following characteristics on Pro mini:
TTL
100kbps
9 Data bits
No parity
1 stop bit

i have 2 implementations:

  1. the 1st uses HW serial for another task so the above must be done with SW serial.
  2. the 2nd uses SW serial for another task, so the above must be done with HW serial.

i have read about some options for method 2, it is not all clear to me yet. but have not found a proper way to do method #1.

any help for both methods would be greatly appriciated. some libs / example codes would be great to have if they are available.

thanks in advance.

Forget #1, SoftwareSerial will never handle 100kbps reliably.

Nick Gammon did a mod of the HardwareSerial class to support 9bit some time ago. You might be able to apply his patch to a current version of the library but you probably have to adapt the patch quite thoroughly.

@i3dm, do not cross-post. Do not hijack. Post removed.

Times four.

@i3dm, do not cross-post again.

@i3dm, do not hijack again.

for(byte CodingBadly = 1; CodingBadly < 5; CodingBadly++)
{
//do your stuff
}

sorry for that guys.
has anyone tested Alt9softserial?

any feedback would be welcome.

has anyone tested Alt9softserial?
GitHub - manuel-rabade/Alt9SoftSerial: Software emulated 9 bit serial using hardware timers for improved compatibility

As I wrote: forget a software emulation at 100kHz on the AVR platform.

any other options?
perhaps using another pro mini with hw serial in a stack mounting?
but as far as i can tell, not even hw serial is available with 9 bits without modifications that are beyond my level?

i3dm:
any other options?
perhaps using another pro mini with hw serial in a stack mounting?
but as far as i can tell, not even hw serial is available with 9 bits without modifications that are beyond my level?

instead of a pro mini, you may want to try a Leonardo Pro Micro which has an additional Hw serial (Serial1) and dimensions close to a pro mini.

and it's not as complicated as you think it is! most of the post you already looked at (and wrote there) has instructions on what to do.... you just need to follow them

I've also attached a 9 bit serial library which you may use if you wish... its the same one as the one in my 9 bit serial post which you saw EXCEPT you do not need to replace any files. Just put the folder in the 'library' folder of your arduino IDE program and try out the example.

Good Luck!

HardwareSerial9bit.zip (13.6 KB)

thank you for your help.
Leonardo pro micro sounds interesting. but i do not see pins for Serial2?

just to verify. i need 2 actual serial connections. none of them is used for USB.
im reading 100k serial data and sending 100k serial data.

Leonardo pro micro sounds interesting. but i do not see pins for Serial2?

Serial2, why can't you use Serial1?

i need 2 actual serial connections. none of them is used for USB.

The Leonardo (or the Pro Micro) has USB built into the main processor. So you can use Serial as the connection to the PC (through a virtual USB serial) and Serial1 to connect to your special device.

im reading 100k serial data and sending 100k serial data.

Should be possible with that setup.

the leonardo has only one pair of serial pins. and i need 2 hardware serials (4 pibs).
where would the second serial connect to?

i do not need any USB capability for anything other than firmware flashing.

i3dm:
the leonardo has only one pair of serial pins. and i need 2 hardware serials (4 pibs).
where would the second serial connect to?

i do not need any USB capability for anything other than firmware flashing.

sounds like the only option for you is to use a MEGA. if size of board is an issue, have a look at the "Mega 2560 PRO MINI" ...

hope that helps.

im afraid that wont work as im using a custom shield on top of it made for a pro mini.

perhaps implement by using 2 hw serials from 2 pro minis in a stack? and i2c communication between them? or any other means of communication that can handle 100kbps?

i3dm:
im afraid that wont work as im using a custom shield on top of it made for a pro mini.

perhaps implement by using 2 hw serials from 2 pro minis in a stack? and i2c communication between them? or any other means of communication that can handle 100kbps?

its really depends on what you are trying to achieve; are you:

  1. simply bridging the 2 networks,
  2. modifying the data before passing it,
    3 anything else... ? ? ?

you have not really been transparent on that matter to be honest and it only makes it difficult for us to help YOU figure out a suitable solution!

im making a telemetry adapter from a RC jet turbine (serial 9 bit 100k) to futaba Sbus2 (serial 8 bit 100k).

the data from the turbine can either be read by ardu1 and sent to ardu2 where it is parsed and send to ardu2, or parsed in ardu1 and sent as data items, it doesnt matter to me.

i3dm:
im making a telemetry adapter from a RC jet turbine (serial 9 bit 100k) to futaba Sbus2 (serial 8 bit 100k).

the data from the turbine can either be read by ardu1 and sent to ardu2 where it is parsed and send to ardu2, or parsed in ardu1 and sent as data items, it doesnt matter to me.

I assume that you already know have to re-package the 9 bit data into a format suitable to Sbus2... curious but will you simply send the first 8 bits as one byte and the 9th bit in another byte?

in any case if you are bent on NOT using a MEGA you could possibly use SPI between the arduinos to transfer the data but this would involve a great lot more deal of code to ensure a robust communication.

i3dm:
im afraid that wont work as im using a custom shield on top of it made for a pro mini.

If it were me, I would simply add pins/wires to your 'custom shield' and connect those to a MEGA. would save a hell lot of coding!!!

i understand what you mean. yes im chaging the data to sbus2 format.
lets assume i need to read 50 bytes into a buffer into ardu1 and send that buffer to ardu2. how complicated is that via spi? perhaps should consider i2c?

i3dm:
i understand what you mean. yes im chaging the data to sbus2 format.
lets assume i need to read 50 bytes into a buffer into ardu1 and send that buffer to ardu2. how complicated is that via spi? perhaps should consider i2c?

had a thought about your porblem and I think you might just be able to be able to achive what you whant to do using the software serial (AltSoftSerial lib) as medium to transfer data between the arduinos.

in pseudo code I would try something like this:

/////////ardu1 (RC jet turbine (serial 9 bit 100k))
union {
uint16_t in;
uint8_t bytes[2];
} data;

//initialise 9 bit hw serial
Serial90.begin(100000);

//initialise AltSoftSerial
altSerial.begin(19200);

if(Serial90.available()){
//read incoming data
data.in = Serial90.read();

//transmit data to ardu2
altSerial.write(data.bytes[1]&0x01); //to send only 9th bit
altSerial.write(data.bytes[0]);
}

/////////ardu2 (futaba Sbus2 (serial 8 bit 100k).)
union {
uint16_t in;
uint8_t bytes[2];
} data;

//initialise hw Serial
Serial.begin(100000, SERIAL_8E2); //SBUS uses inverted serial logic with baud rate of 100000, 8 data bits, even parity bit, and 2 stop bits. will need additional hw for inverting logic

//initialise AltSoftSerial
altSerial.begin(19200);

if(altSerial.available()){
//read incoming data
data.bytes[1] = altSerial.read();
data.bytes[0] = altSerial.read();

//re-package 'data.in' for Sbus2 transmit
//
//

//output data onto Sbus2 bus
Serial.write(Sbus2_data);
}

be aware that with this pseudo code you may face some syncing issues as the RX ardu2 has no means of determining whether the FIRST data its receiving is 'byte[0]' or 'byte[1]' (you would face the same challenge with other transfer media as well btw!) but there are ways to fixing that...

interesting. i can add a couple of header bytes as sync.
but wont it be better to work with something that runs a higher baud? like i2c? as the media.