Problem with applying format to serial communication

12 Nov 2016

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#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();
        }
    }
}