Help with code

Status
Not open for further replies.

0xda71d

New member
Hey, I just got a Teensy 3.1 because it has much more memory than Arduino. This code worked on Arduino, being able to read from any Serial port and saving it to a string. However, this crashes the Teensy. Please tell me what is wrong and give me an explanation about the memory. I tried saving to heap I tried saving to stack, but to no avail. Thanks

I keep getting Available but no output with the code below. Connected to Serial3 is GPS module which works when each byte is printed rather than saved on a string.

Please help.

char readBuffer[1024];

void setup(){
Serial.begin(9600);
Serial3.begin(9600);

}
void loop(){
if(Serial3.available()){
Serial.println("Available");
int howBig = readSerialString(Serial3);
for( int i = 0; i < howBig; i++){
Serial.print(readBuffer);


}
}



}
int readSerialString(HardwareSerial whatSerial){
memset(readBuffer, 0, strlen(readBuffer));
int theSize = 0;
while(whatSerial.available()){
readBuffer[theSize]=(char) whatSerial.read();
theSize++;
//delay(10); I tried delay to no avail.
}
readBuffer[theSize] = (char) 0;
}
 
Thank you for your reply, Paul. I did this, and even hardcoded Serial3 into the function, to no avail. Is there any other thing related to my code that is wrong? Thanks
 
Post the latest copy with Serial3 (remember the "forum rule"....), and I'll take a look tomorrow.

Are you absolutely sure you've got real hardware serial data coming into pin 7 (RX3)?

Also, is the function really returning a number to the main loop() function?
 
Status
Not open for further replies.
Back
Top