1.3.1 The First Instruction Fetch by the CPU Under Certain Conditions Will Fail
The first instruction fetch by the CPU will fail immediately after Power-up, a device Reset, waking up from Sleep, or jumping into an Interrupt Service Routine (ISR). This failure occurs when the device frequency is above 16 MHz (FOSC > 16 MHz).
Work arounds
Option 1: Reduce the device frequency to 16 MHz or below (FOSC ≤ 16 MHz).
Option 2: If the device must operate above 16 MHz:
- Open the Project Properties window (see The First Instruction Fetch by the CPU Under Certain Conditions Will Fail).
- Under the XC8 Linker categories tab, fill in the information as shown
below:
- In the Option categories drop-down menu, select Fill Flash
Memory:
- In the Which area to fill field, select Provide Range to fill
- In the How to fill it field, select Constant or incrementing value
- In the Constant field, enter 0x0
- In the Increment/Decrement field, select No Incrementing
- In the Memory address range field, enter '0x0:0x1
- In the Additional options field, enter
-mdebugger=type, wheretypeis the type of debugger tool used for programming/debugging the device as defined in the table below:Type Debugger selected noneNo debugger icd2MPLAB® ICD 2 icd3MPLAB ICD 3 icd4MPLAB ICD 4 icd5MPLAB ICD 5 pickit2PICkit™ 2 pickit3PICkit 3 pickit4PICkit 4 pickit5PICkit 5 realiceMPLAB REAL ICE™ In-circuit Emulator ice4MPLAB ICE 4 In-circuit Emulator snapMPLAB Snap Figure 1-1. Project Properties "Fill Flash Memory" Option Category Window View 
-
In the Option categories drop-down menu (see Figure 1-2), select Additional options:
- In the Codeoffset field, enter 1
- Press the Apply button, then press the OK button
Figure 1-2. Project Properties "Additional Options" Option Category Window View 
- In the Option categories drop-down menu, select Fill Flash
Memory:
- Add two
NOP()instructions immediately after anySLEEPinstruction(s):#include "mcc_generated_files/system/system.h" int main(void) { SYSTEM_Initialize(); INTERRUPT_GlobalInterruptEnable(); WeatherStation_Initialize(); while(1) { if(tmr1_tick == 1) { WeatherStation_Print(); tmr1_tick = 0; } SLEEP(); // Wait for interrupt NOP(); NOP(); // Ensure instruction pre-fetched while sleeping // is safe to execute on awakening } }
Affected Silicon Revisions
| A2 | A3 | A4 | |||||
| X | X |
