Assigning SAMD51 SERCOM UART to ANALOG PINS

Assigned three unused SERCOM to pins as extra UARTS.
Two work no problem, this one has an issue.

// Serial2
#define PIN_SERIAL2_RX       (17ul)     // 17/PB09
#define PIN_SERIAL2_TX       (16ul)     // 16/PB08
#define PAD_SERIAL2_RX       (SERCOM_RX_PAD_1)
#define PAD_SERIAL2_TX       (UART_TX_PAD_0)
Uart Serial2(&sercom4, PIN_SERIAL2_RX, PIN_SERIAL2_TX, PAD_SERIAL2_RX, PAD_SERIAL2_TX);

And the mux assignment;

  //Serial2 - Sercom4
  pinPeripheral(PIN_SERIAL2_TX,PIO_SERCOM_ALT);
  pinPeripheral(PIN_SERIAL2_RX,PIO_SERCOM_ALT);
  Serial2.begin(115200);  //RS485               // Initialise Serial2 on Sercom4

The problem is that is doesn't work. FOURREGS gives a hint why. The other SERCOM pins are listed as expected but FourRegs shows these two pins as assigned to PMUX group A (0x0) ANALOG instead of group D (0x3) SERCOM_ALT.

Can anyone help me get this going? Is it a problem or limitation of the pinPeripheral function?

PA22:  pmux SERCOM3:0
PA23:  pmux SERCOM3:1(usart:rx) output DRVSTR
PA24:  pmux USB:DM
PA25:  pmux USB:DP
PA27:  input
PA30:  pmux CORTEX_CM4:SWCLK
PA31:  input
EVCTRL:  evt0:OUT,0 evt1=OUT,0 evt2=OUT,0 evt3=OUT,0
--------------------------- PORT B
PB00:  input
PB01:  input
PB02:  input
PB03:  output INEN
PB04:  input
PB05:  input
PB06:  input
PB07:  input
PB08:  pmux ADC0:2,ADC1:0,X1/Y1
PB09:  pmux ADC0:3,ADC1:1,X2/Y2
PB10:  input
PB11:  input
PB12:  input
PB13:  input
PB14:  input
PB15:  input
PB16:  pmux SERCOM5:0
PB17:  pmux SERCOM5:1(usart:rx)
PB18:  input
PB19:  input

Hi pchidley,

The calls to the pinPeripheral() functions should occur after the initialisation of the serial port with Serial2.begin():

//Serial2 - Sercom4
Serial2.begin(115200);  //RS485               // Initialise Serial2 on Sercom4
pinPeripheral(PIN_SERIAL2_TX,PIO_SERCOM_ALT);
pinPeripheral(PIN_SERIAL2_RX,PIO_SERCOM_ALT);

Martin is again correct.. THANKS.

However it is interesting to note that on the other two Sercoms, calling pinPeripheral before the serial port initialization of the serial port did not cause a problem.
I guess this is a symptom of how Arduino tries to make things 'easy' by hiding what goes on behind the functions.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.