Following is the test program. What am I missing?
I should add that I have been using Teensy boards for a few years. I am hoping to migrate to the Nucleo family.
Thank you
Code: Select all
/*
Comms - test communications with host
*/
#include "Arduino.h"
#include <ctype.h>
char rcvbuffer[256];
char sndbuffer[256];
uint16_t nrcvbuf = 0;
int led = 13;
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
Serial.begin(9600);
Serial.println("I'm awake!\n");
}
void loop() {
uint16_t n;
char *pc;
char c;
n = 0;
digitalWrite(led, HIGH); // turn the LED on
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off
delay(1000); // wait for a second
Serial.println( (char *) "Top of loop\n" );
// Read from the serial interface until we find a control character
while ( Serial.available() ) {
c = Serial.read();
if ( !c || iscntrl( c ) ) {
rcvbuffer[nrcvbuf] = 0;
n = nrcvbuf;
nrcvbuf = 0;
break;
}
else if (n < sizeof(rcvbuffer)-1) {
rcvbuffer[nrcvbuf++] = c;
}
else {
Serial.println( (char *)"Error: buffer overflow" );
nrcvbuf = 0;
}
}
// for now, just echo the received buffer
if ( nrcvbuf > 0 ) {
rcvbuffer[nrcvbuf] = '\n';
Serial.println( (char *) rcvbuffer );
}
}