6.4.1.7.1 CN Configuration and Operation
The CN pins are configured as follows:
- Disable the CPU interrupts.
- Set the desired CN I/O pin as an input by setting the corresponding TRISx register bits =
1
. - Enable the CN Module by setting the ON bit (CNCONx[15]) =
1
. - Enable the individual CN input pins, and optional pull-ups or pull-downs.
- Read the corresponding PORTx registers to clear the CN interrupt.
- Configure the CN Interrupt Priority bits, NVIC.IP register.
- Clear the CN Interrupt Flag bit, by setting the corresponding CLRPEND bit in the NVIC.IPCR register.
- 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.
- Enable the CN Interrupt Enable bit by setting the corresponding enable bit in the NVIC.ISER register.
- 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.