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

Thread: Teensy 3.2 -- Corrupted serial port values when run above 48MHz?

  1. #1
    Junior Member
    Join Date
    Dec 2018
    Posts
    4

    Teensy 3.2 -- Corrupted serial port values when run above 48MHz?

    Hello,

    I'm trying to communicate with a Microchip LoRaWAN modem (RN2903) using a Teensy 3.2. It works well when using the code at the bottom.

    The problem is that it only works when I set the CPU speed to 48MHz or slower. When I set it to 72 MHz the join function (ttn.join(appEui, appKey);) causes my program to reset over and over...not sure why this happens. I'm using a baudrate of 57600, which is standard for this modem.

    Anyone have any ideas? This is the code for the library:

    https://github.com/TheThingsNetwork/...ngsNetwork.cpp

    I tried stripping out all of the PROGMEM statements and changed each of the string functions to their original version (for example P_strcpy to strcpy) but that didn't solve the problem.

    It seems like it is some issue with delays, but there are only a couple in that library and changing them doesn't seem to do anything + they are only used for the autobaud feature. Or it could be some issue relating to the fact that the library is written for AVR processors (which is why I tried removing all of the PROGMEM statements and the other calls related to them).


    Code:
    #include <TheThingsNetwork.h>
    
    /* Serial debugging */
    #define debugSerial Serial
    #define DEBUG_SERIAL_BAUD 57600
    
    /* LoraWAN */
    const char *appEui = "70B3D57ED000BDDF";
    const char *appKey = "6C19B3357B72BCC89F3C5170DAB71F99";
    #define loraSerial Serial1
    #define freqPlan TTN_FP_US915
    #define LORA_SERIAL_BAUD 57600
    TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);
    
    void setup() 
    {
      debugSerial.begin(DEBUG_SERIAL_BAUD);
      loraSerial.begin(LORA_SERIAL_BAUD);
      delay(2000);
    
      /* Reset modem */
      pinMode(21, OUTPUT);
      digitalWrite(21, LOW);  
      delay(1000);             
      digitalWrite(21, HIGH);  
      delay(1000);
    
      debugSerial.println("-- STATUS");
      ttn.showStatus();
    
      delay(2000);
      
      debugSerial.println("-- JOIN");
      ttn.join(appEui, appKey);
    }
    
    void loop() 
    {
      delay(1000);
      
      int sensorValue = analogRead(A0);
      float voltage = sensorValue * (3.3 / 1023.0) * 6;
      Serial.println(voltage);
    }

  2. #2
    Junior Member
    Join Date
    Dec 2018
    Posts
    4
    Figured it out. It was a combination of two issues.

    1.) I had to strip out all of the AVR related PROGMEM stuff from The Things Network library. It was causing all of the strings to be corrupted. A working version of the file can be found here: https://pastebin.com/gBdHCAMJ

    2.) When the modem was switching on it was making my voltage regulator hit its current limit, causing everything to reset. Need to add a big capacitor or a regulator that can push more current I guess.

Posting Permissions

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