I have a FRDM-KL27Z dev board communicating with my Mac OSX via the OpenSDA USB port.
It appears that if I write a char to the LPUART with the MSB turned on (i.e. 0x80 - 0xff), the serial line goes idle for one byte period instead of transmitting the character, so if I send the pattern:
putchar(0x55);
putchar(0xa5);
putchar(0x5a);
... on the 'scope (J1-04, aka TX), I see 0x55 followed 10 bit periods of 'mark' followed by 0x5a .
Any idea what's going on?
I'm enabling LPUART0 like this:
lpuart_config_t config;
LPUART_GetDefaultConfig(&config);
config.baudRate_Bps = 9600;
config.enableTx = true;
config.enableRx = true;
CLOCK_SetLpuart0Clock(0x03);
uint32_t uartClkSrcFreq = CLOCK_GetFreq(kCLOCK_McgInternalRefClk);
LPUART_Init(LPUART0, &config, uartClkSrcFreq);
And my putchar() routine looks like this:
void putchar(char ch) {while (!(LPUART0->STAT & LPUART_STAT_TDRE_MASK)) {
// busy wait until TX buffer ready
}
LPUART0->DATA = ch;
}
Solved! Go to Solution.
Hi Robert
Change
void putchar(char ch)
to
void putchar(unsigned char ch)
and it will 'magically' start working.
Regards
Mark
P.S. I think that there was a thread about 4 weeks ago where the same mistake was made, including explanation
Hi Robert
Change
void putchar(char ch)
to
void putchar(unsigned char ch)
and it will 'magically' start working.
Regards
Mark
P.S. I think that there was a thread about 4 weeks ago where the same mistake was made, including explanation
Hah! I just figured it out independently. :smileyhappy:
By declaring it a char (rather than uint8_t), a byte with the MSB set gets sign extended to the full 32 bit LPUART0->DATA register. Bit 13 in the DATA register is FRETSC, or Frame Error / Transmit Special Character. And from the docs: "For writes, indicates a break or idle character is to be transmitted instead of the contents in DATA[T9:T0]. T9 is used to indicate a break character when 0 and a idle character when 1, he contents of DATA[T8:T0] should be zero." Which is exactly what I'm seeing.
So, yep, using a uint8_t will fix all that.
Thanks.