20.2 Software Setup

To setup the Signal Routing Port connection, the user must decide on the source peripheral, the destination peripheral, and whether the source peripheral output needs to be clocked through a flip-flop (data register). If the clocked option is selected, a flip-flop will be introduced into the input path.

  1. Set up the PORTWDF bits to select the pins that need the data flip flop enabled. If the flip-flop is enabled for any Signal Routing Port pin, then select an appropriate clock source using the PORTWCLK register.
  2. Select the appropriate inputs to each bit of the Signal Routing Port using the PORTWINx registers.
  3. Set the input PPS register for the destination peripheral to point to the appropriate Signal Routing Port bit. See the “PPS Inputs” section in the “PPS – Peripheral Pin Select Module” chapter for more information.
  4. If Interrupt-on-Change, DMA or ADC triggers are used, set up the IOCWP and IOCWN registers accordingly.
  5. Initialize the Signal Routing Port by writing to PORTW register. (Optional)
  6. If flip-flop is enabled, enable the clock by setting the appropriate clock enable bit in the PORTWCON register.

Signal Routing Port Setup Example – 4-Bit Shift Register

// Enable flip flops and select appropriate clock
PORTWPDF = 0x0F;   
PORTWCLK = 0x02;

// Point IN[0:3] to RW[n+1] for shift reg
PORTWIN0 = 1;
PORTWIN1 = 1;
PORTWIN2 = 1;
PORTWIN3 = 1;

// Write initial data
PORTW = 0b0110;

// Enable Signal Routing Port clock
PORTWCONbits.CLKEN = 1;

// Turn on the input clock
// and wait for the number of clocks to shift
// then stop the input clock

// Disable Signal Routing Port clock and read shifted data
PORTWCONbits.CLKEN = 0;
uint8_t shiftedData = PORTW;