altSoftSerial for Teensy 4.0 - Cannot compile

Status
Not open for further replies.

CENlaboratory

New member
Hello,

I have been using teensy 3.2 and and XBee with the altSoftSerial.h library (Arduino IDE 1.8.11, latest teensyduino)
I am trying to upgrade to Teensy 4.0 but cannot compile my code. An issue with 'F_BUS not being accessible in this context'.
It compile just file for Teensy 3.2.
Can anyone help?

Thanks,
 
I don't think it has been ported over to T4 or T4.1 yet.

Is there a reason you need it? Instead of just using one of the Hardware Serial ports of the T4? There are 5 Hardware Serial ports on the main pins plus a few others on the bottom pins.

As there are no details given on your usage pattern, not sure if you can simply change over to one of those sets of pin.

Alternatively depending on what pins you are using, you might be able to use my FlexIO stuff, that I have up at: https://github.com/KurtE/FlexIO_t4
I have a setup using these pins to create additional logical serial ports.
 
Hi Kurt,

Thanks for your response and sorry for the brevity of the message.
I am using Sprakfun's Teensy/XBee adaptors (https://www.sparkfun.com/products/13311). I have about 9 devices, building 6 more. Ideally, I just want to swap the teensy (since the pins seem to be compatible). Each of these adaptors is connected to another board full of electronics. It would really be a pain to redesign/rewire everything.
If I understood correctly, the adaptors are pre-wired for RX/TX on 20/21.
In short, unless something real simple can be done on the hardware side, my best bet is just find a way to compile for T4! Any chance someone has already done it, or that the original author could look into it? (I have the feeling it is a matter of setting a few #define parameters...)

Thanks
 
Pins 20 and 21 are on Serial5, not sure if Rex and tx are correct, if so just simple to use it. If reversed maybe you can change on board? Also 20,21 are FlexIO pins so you could create one of those objects, but best to use the hardware serial.
 
Pins 20 and 21 are on Serial5, not sure if Rex and tx are correct, if so just simple to use it. If reversed maybe you can change on board? Also 20,21 are FlexIO pins so you could create one of those objects, but best to use the hardware serial.

According to the schematic, pin 20 is connected as the RX pin (pin 0 if the switch is set for hardware UART) and pin 21 is connected as the TX pin (pin 1 if the switch is set for hardware UART). The Teensy 4.0/4.1 hardware uses pin 21 as the RX pin and pin 20 as the TX pin. So you will need to reverse these two pins (i.e. you cannot use a straight pin to connect the two).

The schematic also mentions AREF which is not present on the Teensy 4.0/4.1. If the Xbee uses AREF, you would need to attach 3.3v to that pin. There are also hook ups for the DAC pin (pin A14 or A12), the two other analog pins (A10/A11). It isn't clear if these are attached to the XBEE. I assume they may not be, but perhaps you should check. The Teensy 4.0/4.1 does not have A10/A11 in the position of the Teensy 3.2 (next to AREF).

The Xbee pinout has CTS/RTS. Note, that in the Teensy 4.0/4.1 that only CTS pin that is available in the outer pins is pin 19 which means you can't use I2C, but it looks like I2C is used by the XBEE. This CTS pin is for Serial3 (pins 14/15). On the Teensy 4.0 there is another CTS pin for Serial5, but it is part of the micro SD pins. In the Teensy 4.1 there are 2 CTS pins, one inside the micro-SD card reader for Serial5, and the other in the memory FLEXSPI pads under the Teensy for Serial8. If you the CTS8 pin, you will not be able to solder the psram or flash memories to the Teensy.

The Teensy 4.0/4.1 does not have a DAC pin. The pin in that position is an on/off pin instead of a DAC.
 
or that the original author could look into it?

I am the original author of AltSoftSerial, and I can say definitively that I have no plans to port AltSoftSerial to Teensy 4.x.

However, Kurt wrote a serial emulation library using FlexIO. I haven't used it. But that library is probably your best path to get more than 7 serial ports on Teensy 4.0 or 8 on Teensy 4.1.
 
Kurt, Michael, thank you so much for the infos. For now I managed by switching the TX/RX source to UART1 on the sparkfun adaptor, and declaring '#define XBee Serial1' instead of 'AltSoftSerial XBee'. Works fine at 19200 bds.

Paul: May I ask why you will not port the software? It's really good... is there something wrong with it? We have been using it pretty much on all our projects... should we stop and re-write our code without it?

Thanks again .
 
Last edited:
Kurt, Michael, thank you so much for the infos. For now I managed by switching the TX/RX source to UART1 on the sparkfun adaptor, and declaring '#define XBee Serial1' instead of 'AltSoftSerial XBee'. Works fine at 19200 bds.

Paul: May I ask why you will not port the software? It's really good... is there something wrong with it? We have been using it pretty much on all our projects... should we stop and re-write our code without it?

Thanks again .

I would guess the main reason is the T4's have a lot of Hardware Serial ports and the FlexIO is setup to allow you to create things like Serial ports...

For example with the library mentioned you can do:

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

FlexSerial SerialFlex(20, 21); // currently setup for pin 2 TX

...

FlexSerial.begin(115200);

And use it like most Serial ports... And works pretty well. For fast RX, it works better on those pins where are on the FlexIO 1 and FlexIO2 objects and not need to use FlexIO3 as The first two have DMA capabilities and the code can be setup to do DMA for the RX, so no issues of losing RX interrupts.
 
Paul: May I ask why you will not port the software?

There is little need when the hardware has 7 or 8 real serial ports.


It's really good... is there something wrong with it?

Yes, there is. AltSoftSerial generates 1 interrupt per rising or falling edge. So on average that's 5 interrupts per byte, and possibly up to 9 or 10 in the worst case. That's a lot better than nothing, and a *lot* better than the CPU hogging of normal SoftwareSerial, but still quite inefficient.

FlexSerial & FlexIO is a much better way for Teensy 4.x.

I may in the (probably distant) future also do something with DMA and timers for SoftwareSerial. But I'm not going to implement serial emulation using timer input capture and output compare when we have so many much better ways on this amazing hardware.
 
Status
Not open for further replies.
Back
Top