7 years, 5 months ago.

Problem with applying format to serial communication

Hello, I've developped simple program that send chars to serial port and can receive chars as well. It works fine until I change word length or parity or stop bits. And I need to set Odd parity because of project requirements. I've tried RealTerm, TerraTerm and CoolTerm. Every of them receiving random chars after changing that settings. I can successfully change baud rate. I'm working on STM32F746G-DISCO

could someone help? thanks in advance.

#include "mbed.h"

DigitalOut myled(LED1);
Serial pc(USBTX, USBRX); // tx, rx
Serial device(D1, D0);  // tx, rx

int i;
char c[10],buffer[10];

void validator() {

    myled = 1; // LED is ON
    wait(0.2); // 200 ms
    myled = 0; // LED is OFF
}

int main() {
    pc.baud(2400);
    pc.format(8,Serial::None,1);
    device.format(8,Serial::None,1);
    device.baud(2400);
    pc.printf("siema!\n");  
    while(1) {
        if(pc.readable()) {
            pc.gets(buffer,3);
            if (strcmp(buffer,"BK")==0) {
                pc.printf("bk\n");
            }
            else {
                pc.printf("error\n");
            }
            validator();
        }
        if(device.readable()) {
            device.gets(buffer,3);
            if (strcmp(buffer,"BK")==0) {
                device.printf("bk\n");
            }
            else {
                device.printf("error\n");
            }
            validator();
        }
    }
}
Be the first to answer this question.