Serial2 on pad 26 and 31 on Teensy 3.1

Status
Not open for further replies.

TimJ

Member
I want to use Serial2 on pad 26 and 31 of a Teensy 3.1, does anyone have code to switch Serial2 to those pads?
Why is TX2/RX2 printed in a different shade on the 'Welcome to Teensy 3.1' card?


Cheers
Tim
 
Anyone with ideas?
I read the MK20DX256 manual and went though the serial sources, but I have no clue so far ...
 
Hi

Pads 26 and 31 are connected to the K20 ports PTE0 and PTE1:
- pad 26 = PTE1 = UART1_RX [RX2 according to Teensy 3.1 nomenclature]
- pad 31 = PTE0 = UART1_TX [TX2 according to Teensy 3.1 nomenclature]

To connect these, the following registers need to be set
PORTE_PCR0 = 0x00000300 (mux 3) - connects alternative function UART1_TX to pin PTE0
PORTE_PCR1 = 0x00000300 (mux 3) - connects alternative function UART1_RX to pin PTE1

[Note that the registers are as according to the MK20DX256 manual - defines and macros used to do this depend on the environment used to program in]

Regards

Mark

P.S. Possibly the RX2/TX2 are printed differently because these are non-preferred pinouts (?)
 
Last edited:
The colouring shows alternate assignments for a pin. For example, pin 26 by default is [edit]A15 but the grayed out box to the left shows that the pin can be reassigned to be RX2 (serial port 2 receive). Pin 13 is the SPI SCK pin but if you need to use the LED on that pin and use SPI as well, you can reassign SCK to pin 14.
I think this is what is needed to make pins 26 and 31 be Serial port 2:
Code:
  // reassign pins 26 and 31 to be Serial port 2 Rx(26) and Tx(31)
  CORE_PIN26_CONFIG = PORT_PCR_MUX(3);
  CORE_PIN31_CONFIG = PORT_PCR_MUX(3);
I haven't got those pins wired up so I can't test it but I am pretty sure that is what is required. Pin 31 might require drive strength enable as well so if it doesn't work well, try this :
Code:
  CORE_PIN31_CONFIG = PORT_PCR_DSE | PORT_PCR_MUX(3);

Pete
 
Last edited:
Great! Thanks a lot guys, both approaches worked.
Now I can proceed to convert my old Graupner mc-17 remote control to Teensy 3.1 / XBee Pro S2B :) http://tim.jagenberg.info/tag/mc-17/
Almost all standard pins were already used up for analogue inputs from the stick, analogue output to ammeter, LCD control, and front buttons.
 
My brain wasn't in gear when I posted that. I should have realized that uTasker had already posted the fix. All I did was use the defines and macros from the Teensy libraries.

Pete
 
Pete

The macros that I use would look like this:

_CONFIG_PERIPHERAL(E, 0, PE_0_UART1_TX);
_CONFIG_PERIPHERAL(E, 1, PE_1_UART1_RX);


To put a pull-up on the input (for example):
_CONFIG_PERIPHERAL(E, 1, (PE_1_UART1_RX | PORT_PS_UP_ENABLE));

They are relative to the Kinetis ports rather than Teensy board pinout.

An improvement to the Teensy library ones could be to use
CORE_PIN26_CONFIG = PORT_PCR_MUX(RX2);

since the mux value to be used can be defined - rather than have to look up the value to put in the PORT_PCR_MUX()

Regards

Mark
 
Last edited:
Status
Not open for further replies.
Back
Top