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

Thread: teensys 3.5 - serial2 problem

  1. #1
    Junior Member
    Join Date
    Oct 2019
    Location
    FRANCE
    Posts
    1

    teensys 3.5 - serial2 problem

    Hello,

    I use Teensys 3.5 and a serial IMU. My program work with SoftwareSerial but no with Serial2.
    I use 9 and 10 pins (serial 2 on teensys 3.5)

    Can anyone provide help for this problem ? thanks.

    Code with Serial2 :

    Code:
    #define CMPS12 Serial2
    
    const byte rxPin = 9;
    const byte txPin = 10;
    
    void IMU_init(void)
    {
      Serial.println("Init IMU...");
    
      delay(1000);
    
    
      CMPS12.setRX(rxPin);
      CMPS12.setTX(txPin);
    
    	CMPS12.begin(9600);
    
      // BAUD 38400
      CMPS12.write(0xA1);
      delay(500);
      
      CMPS12.begin(38400);
    
    }
    Code with SoftwareSerial :

    Code:
    SoftwareSerial CMPS12 = SoftwareSerial(9,10);
    
    void IMU_init(void)
    {
      Serial.println("Init IMU...");
    
      delay(1000);
    
    
      //CMPS12.setRX(rxPin);
      //CMPS12.setTX(txPin);
    
      CMPS12.begin(9600);
    
      // BAUD 38400
      CMPS12.write(0xA1);
      delay(500);
      
      CMPS12.begin(38400);
    
    }
    Thanks.

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,918
    Note sure what part is not working … does first Serial2 print work but not the second or neither work?

    Those pins 9 and 10 are the native primary pins for Serial2 so these lines in first code block are not needed or helping anything:
    Code:
      CMPS12.setRX(rxPin);
      CMPS12.setTX(txPin);
    As in the second code block they can/should be commented out.

    That code is not a complete runnable sketch so not known how soon after setup() entry this code is running - it isn't clear if the Serial will be ready to print : Serial.println("Init IMU...");

    Serial2 should be ready okay but … what device is on the other end? Has it had time to power up and is it ready for the first print?

    Does SoftwareSerial use the standard N,8,1 delivered with the Serial2.begin()?

Posting Permissions

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