Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 5 months ago.
This declaration has no storage class or type specifier "include mbed.h"
I'm receiving this error: This declaration has no storage class or type specifier "include mbed.h"
Following is my code: include "mbed.h" Serial pc(USBTX, USBRX); Serial bluetooth(D2,D8); int main(){ int i; int j=10; char c[j]; bluetooth.printf("Ready to recieve data"); pc.printf("Ready to recieve data"); for(i=0,i<j,i++) { c=bluetooth.getc(); bluetooth.printf(" 0x%.2x",c[i]); pc.printf("0x%.2x",c[i]); } }
1 Answer
6 years, 5 months ago.
The preprocessor include of course needs the pound sign, #include "mbed.h"
You need to end your printf statements with a newline to flush the buffer and actually send the characters.
You should check if a serial char is available before trying to read it.
In your loop you need to take into account that you will not have a new character every time through the loop. So you need to count chars received.
Probably want to add a small wait to the loop to free up cpu to do other things.
You generally should never exit main().
This might be a starting point, to read chars and simply echo them back.
#include "mbed.h"
Serial pc(USBTX, USBRX);
Serial bluetooth(D2,D8);
int main(){
int i = 0;
char c;
int count = 0;
bluetooth.printf("\n\nReady to recieve data\n");
pc.printf("\n\nReady to recieve data\n");
while (true) {
while(bluetooth.readable()) {
c=bluetooth.getc();
bluetooth.printf("%c\n",c);
pc.printf("%c\n",c);
pc.printf("%d\n", ++count);
}
wait(0.01);
}
}