So I am starting a project and working on the serial buffer routines. I am using a serial interrupt to read characters and buffer them to an array of characters. Whenever I get a carriage return (=13) I set sFlag=1 so the main program can pick it up and print the string to the serial. It works mostly but behaves weird depending on the amount of characters sent to the buffer. Some letters get overwritten and some are just missing etc. Can anyone help me get this sorted out please.
#include "mbed.h"
#include "MobileLCD.h"
#include "QEI.h"
QEI wheel (p29, p30, p28, 500);
MobileLCD lcd(p5, p6, p7, p8, p9);
Serial pc(USBTX,USBRX);
DigitalOut led(LED1);
DigitalOut led2(LED2);
char buff[100];
int sFlag=0;
int i=0;
void Serialint() {
led=!led;
buff[i]= pc.getc();
if (buff[i]==13) {
sFlag=1;
//i=0;
} else {
i++;
}
}
int main() {
pc.baud(115200);
pc.attach(&Serialint);
lcd.locate(0,0);
lcd.printf("Count is:");
pc.printf("Matt's Serial!!\n\r");
while (1) {
// wait(0.1);
// lcd.locate(0,1);
// lcd.printf("%10i", wheel.getPulses());
if (sFlag==1) {
sFlag=0;
pc.printf("%s\n\r",buff);
i=0;
if (strcmp(buff,"tenletters")==0) {
led2=1;
} else {
led2=0;
}
}
}
}
So I am starting a project and working on the serial buffer routines. I am using a serial interrupt to read characters and buffer them to an array of characters. Whenever I get a carriage return (=13) I set sFlag=1 so the main program can pick it up and print the string to the serial. It works mostly but behaves weird depending on the amount of characters sent to the buffer. Some letters get overwritten and some are just missing etc. Can anyone help me get this sorted out please.