To set or clear the IOLOCK bit, an unlock sequence must be executed:


#define PPSUnLock() {SYSKEY=0x0; SYSKEY=0xAA996655; SYSKEY=0x556699AA; CFGCONbits.IOLOCK=0;}
#define PPSLock() {SYSKEY=0x0; SYSKEY=0xAA996655; SYSKEY=0x556699AA; CFGCONbits.IOLOCK=1;}

Note these defines are likely already included in xc32

UART

	DISABLE_INT;
	PPSUnLock()				//PPS Unlock (required before setting peripheral pin, if config bit IOL1WAY is set only 1 change of IOLOCK is permitted)
	//Input
	U1RXRbits.U1RXR = 0x04;		//RPB2
	//Output
	CFGCONbits.IOLOCK = 0;
	RPB3Rbits.RPB3R = 0x01;		//U1TX
	PPSLock();				//PPS Lock
	ENABLE_INT;		//<<<if irqs have been set!
SPI

	//----- SPI2 -----
	DISABLE_INT;
	PPSUnLock()				//PPS Unlock (required before setting peripheral pin, if config bit IOL1WAY is set only 1 change of IOLOCK is permitted)
	//Input
	SDI2Rbits.SDI2R = 0x03;		//RPD11
	//Output
	RPB3Rbits.RPB3R = 0x06;		//SDO2
	PPSLock();				//PPS Lock
	ENABLE_INT;		//<<<if irqs have been set!

 

 

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.