Teensy 3.1: Problem using Serial2 on pins 26 & 31

Status
Not open for further replies.

maxbot

Active member
Serial2 not working on pins 26 & 31 (Teensy 3.1)

I have a problem with using serial2 on pins 26 & 31. What I want to do is read images from a VC0706 serial CMOS camera.
Using standard serial1 ports (0 & 1), it does work. As I need them for other peripherals I decided to connect the camera to the alternative pins on HardwareSerial2.
I found this thread: http://forum.pjrc.com/threads/25357-Serial2-on-pad-26-and-31-on-Teensy-3-1 where a user wanted to do the same.
The proposal was:
Code:
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

So I went into the file "mk20dx128.h" and changed the two lines as followed:
Code:
#define PORTE_PCR0		*(volatile uint32_t *)0x00000300  // Pin Control Register n
#define PORTE_PCR1		*(volatile uint32_t *)0x00000300  // Pin Control Register n

Instead of passing the Serial1 object to the camera, I am now using : "Camera cam = Camera(&Serial2);"
Unfortunately, the cam is not responding on those new ports. Am I missing something ?
Thanks for your help !
 
Last edited:
You don't edit the mk20dx128.h file. These two statements go in your setup() function.
Code:
PORTE_PCR0 = 0x00000300;
PORTE_PCR1 = 0x00000300;

[edit] You might find this code easier to use since it uses the Teensy pin numbers
Code:
  // reassign pins 26 and 31 to use the ALT3 configuration
  // which makes them  Serial port 2 Rx(26) and Tx(31)
  CORE_PIN26_CONFIG = PORT_PCR_MUX(3);
  CORE_PIN31_CONFIG = PORT_PCR_MUX(3);
It does the same thing.

Pete
 
Last edited:
Thanks for your answer. I have set the values inside the mk20dx128.h back to their standard values and put your two lines inside the setup() function.
But I still have no success :(
Is there any difference on that pins compared to the standard ones ?
 
I wired up the alternate Serial2 port and this sketch works for me with putty receiving "Hi there" on the PC:
Code:
// Test Serial2 on reassigned pins 26 and 31
// This works!
void setup(void)
{
  Serial.begin(9600);
  while(!Serial);
  delay(1000);
  Serial.println("Start");
  
  // reassign pins 26 and 31 to use the ALT3 configuration
  // which makes them  Serial port 2 Rx(26) and Tx(31)
  CORE_PIN26_CONFIG = PORT_PCR_MUX(3);
  CORE_PIN31_CONFIG = PORT_PCR_MUX(3);
  
  Serial2.begin(9600);
  Serial2.println("Hi there");
  
}

void loop(void)
{
}

Pete
 
Status
Not open for further replies.
Back
Top