11 years, 2 months ago.

Serial Parity Issue

Hi,

I'm attempting to use a parity bit within my application with little success. To eliminate an issue with my code I've tried to incorporate a parity bit into a simple application (as shown below) and this doesnt appear to work either. I would expect, as there appears to be no error handling, that the receiver would just scrap the incomming packet. What I see is the receiver acknowledging any character transmitted using a standard hyperterminal configured with both odd and even parity.

Can anyone see what I'm doing wrong? Has anyone used the parity check within serial.h?

#include "mbed.h"
 
DigitalOut led1(LED1);
DigitalOut led2(LED2);
 
Serial pc(USBTX, USBRX);
 
void callback() {
    // Note: you need to actually read from the serial to clear the RX interrupt
    printf("%c\n", pc.getc());
    led2 = !led2;
}
 
int main() {
    pc.format(8,Serial::Odd,1);
    pc.attach(&callback);
    
    while (1) {
        led1 = !led1;
        wait(0.5);
    }
}

Question relating to:

1 Answer

11 years, 1 month ago.

The documentation does not say explicitly but it would be unusual for the code to discard RX characters with bad parity - you sometimes want to see these. I guess you'll have to read the line status register yourself directly and check the PE bit (2). See also http://mbed.org/forum/mbed/topic/1201/