My code tries to configure the CAN device, but it never leaves configuration mode. Why?
Well, it turned out that if you connect a CAN transceiver to the CAN pins on the PIC, but fail to supply it with power, then the PIC never leaves configuration mode. Connecting the transceiver to a reliable power source solved the problem.