Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support other than 8N1 framing #1

Open
werk-xyz opened this issue Sep 6, 2015 · 1 comment
Open

Support other than 8N1 framing #1

werk-xyz opened this issue Sep 6, 2015 · 1 comment

Comments

@werk-xyz
Copy link

werk-xyz commented Sep 6, 2015

Hello,

thanks for this great SoftSerial implementation for ESP8266.
It would be great if your library would support other than 8N1 Implementations of serial packet data framing (e.g. 7E1).

@scottwday
Copy link
Owner

Hi, thanks.
8 bit frames are pretty baked in to the code, but 8N1, 7E1 and 7O1 all use 8 bit frames.
For parity just check the MSb of the received byte.

The following code will calculate the parity for a byte by looking up the parity for each nibble:

byte calculateBitCountMod2(byte n)
    {
        const unsigned short bitCounts = 0b0110100110010110;
        return ((bitCounts >> (n >> 4)) ^ (bitCounts >> (n & 0x0F))) & 1;
    }

so you could do something like

    byte rxData = rxByte & 0x3F;
    bool parityOkay = (calculateBitCountMod2(rxData) << 7) == (rxByte & 0x80)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants