6.4.1.7.1 CN Configuration and Operation

The CN pins are configured as follows:

  1. Disable the CPU interrupts.
  2. Set the desired CN I/O pin as an input by setting the corresponding TRISx register bits = 1.
  3. Enable the CN Module by setting the ON bit (CNCONx[15]) = 1.
  4. Enable the individual CN input pins, and optional pull-ups or pull-downs.
  5. Read the corresponding PORTx registers to clear the CN interrupt.
  6. Configure the CN Interrupt Priority bits, NVIC.IP register.
  7. Clear the CN Interrupt Flag bit, by setting the corresponding CLRPEND bit in the NVIC.IPCR register.
  8. Configure the CN pin interrupt for a specific edge detect using the EDGEDETECT bit in the CNCONx register, and set up edge control using the CNENx/CNNEx bits.
  9. Enable the CN Interrupt Enable bit by setting the corresponding enable bit in the NVIC.ISER register.
  10. Enable CPU interrupts.

The CNSTATx/CNFx registers indicate whether a change occurred on the corresponding pin since the last read of the PORTx bit. The CNFx registers indicate the type. When a CN interrupt occurs in the Mismatch mode, the user must read the PORTx register associated with the CN pins. This will clear the mismatch condition and set up the CN logic to detect the next pin change. The current PORTx value can be compared to the PORTx read value obtained at the last CN interrupt or during initialization and used to determine which pin changed. The CN pins have a minimum input pulse-width specification. See Electrical Characteristics from Related Links.