Wow, so in simplifying the code to help someone else figure this out, I fixed the issue, sort of.
New code:
#include "mbed.h"
Serial port(p9,p10);
Serial pc(USBTX, USBRX); // tx, rx
DigitalOut myled1(LED1);
void sendCmd(char* cmd)
{
char res[25];
port.printf(cmd);
port.scanf("%s", res);
port.scanf("%s", res);
pc.printf(res);
pc.printf("\n\r");
return;
}
int main() {
//myled1 = 0;
pc.printf("HI!\n\r");
char getFirmwareInfoCMD[] = "$4F00\r";
port.baud(38400);
sendCmd( getFirmwareInfoCMD );
myled1 = 1;
return 0;
}
For some reason, this code still causes the reset, but if I uncomment that first line in main, "myled1 = 0", the mbed only resets 5 or 6 times, then it's fine.
Another fix is to exit out of Tera Term or whatever program has an open connection to the mbed's USB serial port. That is, if the mbed is in its loop where it is reseting like crazy, if I close the listener program on my PC, the mbed immediately stops resetting.
Any explanations?
Edit: It's also important to note that the problem is also realted to the data I am getting from my serial device. If I take out the second scanf in the sendCmd, things seem to work.
Hey,
I have a short bit of code that is causing my mbed to restart and I'm not sure why.
Every time the code returns from the sendCmd function, the chip resets. As you can see from the code, I get stuck in a infinite loop where the code almost finishes executing, but at the return from sendCmd, it resets (the power light flashes), and then it starts executing from the beginning. Sample output following the code.
Also, I inlined the sendCmd function and everything worked fine. I need to call the sendCmd function about 10 times, so I would hate to copy and paste that bit of code over and over.
Sample output: