define(`TITLE', `Teensy meets "not so standard" UART configuration')
define(`DATE', `2014-03-11')
define(`CONTENT', `
The people at https://www.pjrc.com/teensy/index.html did a really good job with the Arduino integration Teensyduino. Thank you very much indeed.
Unfortunately they missed a feature which has been integrated in the Arduino library sometimes between version 1.0.5 and 1.5.2, don'`t know when exactly: advanced UART configuration.
In the documentation of Serial.begin(...)
you see the option to give a config
argument, where in particular you can configure the frame length, the parity and the number of stop bits.
While this is certainly not a very common feature, I need it in my MeterBus projects, since communication on the MeterBus is serial communication with an even parity enabled.
So far I was too lazy to put the stuff into a library, but this is required to enable even parity:
#include <mk20dx128.h> // [...] // this is the new Arduino way of setting parity //Serial3.begin(2400, SERIAL_8E1); // this is the Teensy (Freescale K20) way: Serial3.begin(2400); UART2_C1 |= UART_C1_PE | UART_C1_M;Find the documentation for the
UARTx_C1
register on page pp. 1055-1056, cp. 45.3.3 of the Freescale K20 manual (find that one on the Teensy homepage at https://www.pjrc.com/teensy/datasheets.html).
Note: it is not enough to enable parity (setting the bit UART_C1_PE
, you also need to increase the frame length to 9 bit by setting bit UART_C1_M
, since the frame length seems to include the parity bit.
Right, this is a hack, and maybe the Teensy people will integrate it into the library the other day, but at least for the moment it works for me.
')