Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Help with code

  1. #1
    Junior Member
    Join Date
    Oct 2014
    Posts
    2

    Help with code

    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[i]);


    }
    }



    }
    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;
    }

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    28,479
    Try changing the function to this: (add the "&")

    Code:
    int readSerialString(HardwareSerial & whatSerial){

  3. #3
    Junior Member
    Join Date
    Oct 2014
    Posts
    2
    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

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    28,479
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •