11 years, 2 months ago.

Serial print fails for 15 lines then works

I published program and output to jimspruell/serial_print but here it is

  1. include "mbed.h"

DigitalOut myled(LED1);

  1. define acm 1
  1. if acm==1 Serial serial(USBTX, USBRX);
  2. endif

void print_stng(char *stng) operate at low priority {

  1. if acm == 0 printf( "%s",stng);
  2. else serial.printf( "%s",stng);
  3. endif }

char stng[300]; int pass; int main() { pass=0; wait(2.0);

  1. if acm == 1 serial.baud(115200); set baude rate if serial port
  2. endif

wait(2.0); while(1) { sprintf(stng,"printstring 1 %d \r\n",pass++); print_stng(stng); myled = 1; wait(2.0); sprintf(stng,"printstring 2 %d \r\n",pass++); print_stng(stng); myled = 0; wait(2.0); } }

/* here is the crazy output of minicom set to 115200 baud on a Ubuntu linux systems prinsting 0 printstring 2 1 pristring 1 2 pritstring 2 3 pristring 1 printstring 5 printstring 1 6 printstng 2 7 �ά��߬

�ά��ߍ J8�ά ά�ϬZ8printsri prinstr 2 15 printstring 1 16 printstring 2 17 printstring 1 18 printstring 2 19 printstring 1 20 printstring 2 21 printstring 1 22 printstring 2 23 printstring 1 24 printstring 2 25 printstring 1 26 printstring 2 27 correct from here on

  • /

2 Answers

11 years, 1 month ago.

Please use <<code>> and <</code>> tags around your posted code to keep it readable on this page.

Problem looks like overrun of characters because baudrate is too high or the I/F chip is slow or terminal software is messed up. Try a slower baudrate (eg 9600). Does the problem disappear?

Jim Spruell
poster
11 years, 1 month ago.

I changed to 9600 baud in software and Minicom still failed after 5 lines now.

changed code to: <code>

  1. include "mbed.h"

DigitalOut myled(LED1);

int pass; int main() { pass=0;

wait(2.0); while(1) { printf("printstring 1 %d \r\n",pass++); myled = 1; wait(2.0); printf("printstring 2 %d \r\n",pass++); myled = 0; wait(2.0); } }

</code>

and still fails after 5 lines!! on two different Freescale KL25Z cards

then I moved to a diffrent Ubuntu linux PC and it worked as it should. Guess it was the USB serial driver or Minicom on the one PC???? If I figure out what it was will let you-all know.