SoftSerial - 7 data bits, 2 stop bits

Hi,

Is there any possibility to change configuration in the software serial library to 7 data bits, 2 stop bits and even parity? I have 2 sensors that have these communication parameters, I'm afraid that I have to do some changes in the library. Could anyone help me?

Thanks a lot.

Have you looked at the SoftwareSerial code? A collection of bits is received by the recv() function, which contains this:

    // Read each of the 8 bits
    for (uint8_t i=0x1; i; i <<= 1)
    {
      tunedDelay(_rx_delay_intrabit);
      DebugPulse(_DEBUG_PIN2, 1);
      uint8_t noti = ~i;
      if (rx_pin_read())
        d |= i;
      else // else clause added to ensure function timing is ~balanced
        d &= noti;
    }

    // skip the stop bit
    tunedDelay(_rx_delay_stopbit);
    DebugPulse(_DEBUG_PIN2, 1);

Doesn't look like it would be all that difficult to read 7 bits and skip two stop bits.

szopa89:
Is there any possibility to change configuration in the software serial library to 7 data bits, 2 stop bits and even parity?

You can probably do that with hardware serial if you just tweak a couple of registers as per the datasheet. Why do you have to use software serial?

You can probably do that with hardware serial if you just tweak a couple of registers as per the datasheet. Why do you have to use software serial?

I have arduino uno with one hardware serial which communicate with the program on my computer via USB. I have 2 sensors with rs232 interface(7-E-2 configuration) and I have to get data from them. That's why I need two software serials.

    // Read each of the 7 bits

for (uint8_t i=0x1; i<0x80; i <<= 1)
    {
      tunedDelay(_rx_delay_intrabit);
      DebugPulse(_DEBUG_PIN2, 1);
      uint8_t noti = ~i;
      if (rx_pin_read())
        d |= i;
      else // else clause added to ensure function timing is ~balanced
        d &= noti;
    }

// two stop bits
    tunedDelay(_rx_delay_stopbit);
    DebugPulse(_DEBUG_PIN2, 1);
    tunedDelay(_rx_delay_stopbit);
    DebugPulse(_DEBUG_PIN2, 1);

Is that correct modification of the code?

Is that correct modification of the code?

I'm pretty sure that for loop isn't write.

That's why I need two software serials.

You can't listen to two software serial ports at the same time. If that is a problem, you WILL need to get a Mega.

PaulS:

Is that correct modification of the code?

I'm pretty sure that for loop isn't write.

Hmm, could you tell me what's wrong?

PaulS:

That's why I need two software serials.

You can't listen to two software serial ports at the same time. If that is a problem, you WILL need to get a Mega.

I know. I don't need to listen to devices at the same time. The program will poll devices in a loop one by one.

szopa89:
Hi,

Is there any possibility to change configuration in the software serial library to 7 data bits, 2 stop bits and even parity? I have 2 sensors that have these communication parameters, I'm afraid that I have to do some changes in the library.

You are just reading? You don't need to skip the second stop bit for the simple reason that a stop bit is a "1", and it doesn't matter how many 1s there are before the next start bit. There could be 20 and it wouldn't matter.

And as for the even parity, if you have 7 data bits, the parity will effectively be the 8th bit. Simply ignore it. eg.

byte foo = Sensor.read () & 0x7F;

Done!