Unable to evaluate strings received from UART on mbed LPC1768

Hi all,

recently I encountered a strange problem on my mbed LPC1768 where I wish to evaluate string commands received on UART (at the moment, USB serial). The strings are not firmly defined yet, they should contain an alphabetic code to identify a device and a numeric value which would be a desired position like DEV1,0800.
The problem is, whichever example code I use (I also tried to develop my own code based on an NXP Kinetis KE06 firmware, which is working fine on that machine), all will fail to capture anything from the string: I am unable to detect any character. Everything is echoed back correctly, but nothing can be evaluated. I tried strtok, strchr, etc. all will return NULL. Does anybody have any idea what is happening here and how I should approach this task?

Thanks in advance.

Best regards,
Károly Beneda.

P.S.: Here is my last code in which I just tried to find out whether characters alone could be separated, but nothing happens (echo comes fine, but value remains always zero)

#include “mbed.h”

Serial pc(USBTX,USBRX);
PwmOut led(p21);
float brightness = 0.0;

int main() {
pc.printf(“Press ‘u’ to turn LED1 brightness up, ‘d’ for down\n\r”);
while(1) {
char c = pc.getc();
wait(0.001);
if ((c == ‘u’) && (brightness < 0.1)){
brightness += 0.001;
led = brightness;
}
if ((c == ‘d’) && (brightness > 0.0)){
brightness -= 0.001;
led = brightness;
}
pc.printf("%c %0.3f \n\r",c,brightness);
}
}

Hello Károly,

Nothing seems to be wrong with your code. After replacing

PwmOut led(p21);

with

PwmOut led(LED1);

it works fine on my LPC1768.

I’d suggest to check the settings of your serial terminal program and the LED connected to the pin p21. Maybe you should swap the wires.

NOTE: To get the code formatted, in your post add a line with three backtick characters (available over the same key as the “~” character) at the begin and end of your code.

Hello Zoltán,

thank you very much for your prompt reply, I could not imagine that the solution is so close to me. I use the Bray Terminal, which was fine with older/less sophisticated MCU’s (MS9S08DZ60, MKE06) but now it made some headache and wasted time… I tried the LED1 output, it did not produce anything, because the problem was inside the terminal software itself.
Now I changed to Tera Term, and immediately everything works, the LED brightness is changing, and if I use my old code from the Kinetis, it can be parsed into the desired parts… So thank you again for your valuable answer!

I’m glad you solved the issue :slight_smile: . Actually, I removed the part related to serial terminal from my answer. But I better put it back to make the posts consistent.