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);
}
}