Does a software reset clear the GPIOs state on PIC24?

112 views Asked by At

I am trying to find out if a software reset would cause the GPIO state to default back to a reset states on PIC24F?

The reset command i would like to use:

asm ("reset");

I could not find the answer in the documentation so i tried the following tests.

Test 1:

(pseudo code). 
start firmware
wait 5 sec
turn LED on
wait 2 sec
reset soft using the code -> asm ("reset");

When this reset method is use, the behavior is as follow.
power on
LED off for 5 seconds
LED on for 2 seconds
...
LED off for 5 seconds
LED on for 2 seconds

Test 2:

(pseudo code). 
start firmware
wait 5 sec
turn LED on
wait 2 sec
reset soft using the code -> ((void(*)())NULL)();

When this "reset" (jump) method is use, the behavior is as follow.
power on
LED off for 5 seconds
LED on indefinitelly after

Can someone answer the initial question and explain why the PIC behave this way ?

2

There are 2 answers

0
Mike On BEST ANSWER

Test 1 will perform a Hard reset, i.e. every PIN will reset to whatever default the Datasheet specifies.

Test 2 will not perform a Hard Reset, it will JMP to the Reset Address, which from memory is 0x0 on the PIC24.

Now, in both cases the Firmware will reinitialize (restart) and that in most cases is where the GPIO, etc would be set as per the Software requirements. It looks like your code doesn't set any GPIO as part of the Firmware.

2
the busybee On

The software instruction reset triggers a hardware reset and is as such comparable with a "real" hardware reset. See the specific manual of your device for details. For example, the clock source might not change.

In contrast, your second attempt is just a jump to the reset address. This does not affect GPIO states.


Note: As always in embedded development, you need the manual to understand what you do. If you don't read it, you are "programming by accident" and will have a hard time.