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 Figure 1-1), and 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
, wheretype
is the type of debugger tool used for programming/debugging the device as defined in the table below:Type Debugger selected none
No debugger icd2
MPLAB® ICD 2 icd3
MPLAB ICD 3 icd4
MPLAB ICD 4 icd5
MPLAB ICD 5 pickit2
PICkit™ 2 pickit3
PICkit 3 pickit4
PICkit 4 pickit5
PICkit 5 realice
MPLAB REAL ICE™ In-circuit Emulator ice4
MPLAB ICE 4 In-circuit Emulator snap
MPLAB 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 - Add two
NOP()
instructions immediately after anySLEEP
instruction(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 } }
- Open the
Project Properties window (see Figure 1-1), and under the XC8
Linker categories tab, fill in the information as shown
below:
Affected Silicon Revisions
A2 | A3 | A4 | |||||
X | X |