FlexSerial on a Teensy 4.1

ForbinOne

New member
I am trying to solve the Flexserial library usage on a Teensy 4.1 with pins 2,3,4,5 as serial outputs, to communicate at 9600 BAUD with an APC220 connected on either of the four pins.

I am getting question marks on the receiving APC220 which implies that there is a baud rate issue. If I connect serial1 then the text is clear and the link radio link functions.

This is my code

Code:
#include <FlexIO_t4.h>
#include <FlexSerial.h>

#define TX_PIN 3
#define TX_FLEX_IO_INDEX 0
#define TX_FLEX_IO_TIMER 0
#define TX_FLEX_IO_SHIFTER 0
#define TX_PIN2 4
#define TX_FLEX_IO_INDEX2 0
#define TX_FLEX_IO_TIMER2 1
#define TX_FLEX_IO_SHIFTER2 1
FlexSerial SerialFlex(-1, TX_PIN, -1, -1, -1, TX_FLEX_IO_INDEX, TX_FLEX_IO_TIMER, TX_FLEX_IO_SHIFTER);
FlexSerial SerialFlex2(-1, TX_PIN2, -1, -1, -1, TX_FLEX_IO_INDEX2, TX_FLEX_IO_TIMER2, TX_FLEX_IO_SHIFTER2);

void setup() {
  pinMode(13, OUTPUT);
  while (!Serial && millis() < 4000);
  Serial.begin(9600);

  Serial1.begin(9600);

  delay(500);
  SerialFlex.begin(9600);
  SerialFlex2.begin(9600);
}


void loop() 

{


  Serial.println ("Line Transmitted");

  Serial1.println("Sending A Transmission on Serial1");
  
  SerialFlex.print("Sending A Transmission on Flex");
  SerialFlex2.print("Sending A Transmission on Flex 2");
  

  delay(1000);


}
 
Last edited by a moderator:
I will try to take a look at this later today or tomorrow.

It may be there is an issue going that slow (9600)
 
As I suspected FlexSerial can not work at that low of a baud rate:

I did push up some changes to the library:
https://github.com/KurtE/FlexIO_t4

That properly used the Clock Registers (CCM) that control the FLXIO1/FlexIO2(and 3) settings.

By default FlexIO clock runs at 480mhz/16 and the clock divider counter is 8 bits ...
So the slowest baud that can work is about 58,594

Now if you run at the slowest FlexIO clock speed like:
Code:
  FlexIOHandler::flexIOHandler_list[0]->setClockSettings(3, 7, 7);
  FlexIOHandler::flexIOHandler_list[1]->setClockSettings(3, 7, 7);
  SerialFlex.begin(9600);
  SerialFlex2.begin(9600);
The first one sets the FlexIO registers for FlexIO1, the second call does it for FiexIO12 and FlexIO3

But this only slows it down by factor of 4 so lowest baud is about: 14,648
 
Back
Top