11 years, 4 months ago.

Problem with 8th bit on putc serial

putc is working with both the Serial class and the USBSerial class, and thus I am able to send on either USB connection on the KL25Z. BUT: this only works with values 0x00-0x0f. 0x10-oxff all get turned into 0xf0. I have double, triple, and quadruple checked the COM settings (I just use 9600, 8 bits per byte, no parity, and 1 stop bit) in both my mbed program, and in the COM monitoring programs. I have tried a couple of different COM monitoring programs, and both see 0xf0 instead of the correct value, so I am assuming this is on the mbed end of things.

2 Answers

11 years, 4 months ago.

I ran the following code:

#include "mbed.h"

Serial pc(USBTX, USBRX);
int main() {
    for (int i = 0; i<256; i++)
        pc.putc(i);
    
    while (1) {
        
    }
}

And used Matlab to receive (Teraterm isn't exactly useful for getting binary data), with:

fread(s1, s1.BytesAvailable, 'uint8')

(and s1 serial object). Can copy paste the result, but won't add much, it is a nice list from 0 to 255.

11 years, 4 months ago.

if you can spair the overhead, then send as TWO ASCII bytes,

eg. $A7

becomes $41, $37

or a little faster just add $30, to each nibble, so you end up with:

0,1,2,3,4,5,6,7,8,9,:,;,<,=,>,?

for 0123456789abcdef

don't forget to send both nibbles.

??

try using unsinged char first ????

Cheers

Ceri