Now I splitted the state machines, and RX and TX no longer conflict! So transmission is working correctly. However, now I cannot receive anything... Not sure whether it is a OS thing or my code. I am way too depleted of glucose to continue today
https://pastebin.com/jziyaC0rNote that I doubled the TIMER2 clock, so for B4800, the clock should be set to 9600Hz. These are some settings:
Code: Select all
/**
* @brief B4800 on 7372800Hz Clock
*/
const SerialConfig softserial_config = {
UBRR(4800), /* No use, just a placeholder.*/
USART_CHAR_SIZE_8,
96,
(1 << CS21) /* Divide 8.*/
};
/**
* @brief B4800(approx) on 16000000Hz Clock
*/
const SerialConfig softserial_config = {
UBRR(4800), /* No use, just a placeholder.*/
USART_CHAR_SIZE_8,
208,
(1 << CS21) /* Divide 8.*/
};
I will probably make use of that UBRR thing after I get serial working. Here is the current symptom. For a main thread like this:
Code: Select all
while (true) {
debug("USART1\r\n");
chThdSleepSeconds(1);
chprintf((BaseSequentialStream *)&SDS, "USARTS\r\n");
chprintf((BaseSequentialStream *)&SDS, "USARTS Press A Key > ");
{
char x = sdGet(&SDS);
chprintf((BaseSequentialStream *)&SDS, "%d\r\n", x);
}
chThdSleepSeconds(1);
}
USART1 works of course, and USARTS prints are perfect. However, the program doesn't read anything to `x`. For now, I can't find the reason yet. Here is a snippet of output:
Code: Select all
USARTS Press A Key > USARTS
USARTS Press A Key > USARTS
USARTS Press A Key > �����������������������������������������������������������������������������������������������������������������������������
Those garbage at the end generates once per second. Not sure where they come from(maybe Q_EMPTY?), and don't know why the period is one second instead of two. However, if I actually try to type, garbage stops appearing. After I stop, garbage shows up a second later.
I will investigate the problem slightly later.