Software Setup

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

Virtual Port Setup Example – 4-Bit Shift Register

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

// Point IN[0:3] to RW[n+1] for shift reg

// Write initial data
PORTW = 0b0110;

// Enable Virtual Port clock

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

// Disable Virtual Port clock and read shifted data
uint8_t shiftedData = PORTW;