Program randomly hangs on MCLR reset

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

Program randomly hangs on MCLR reset

Post by GTF »

Hello

I have come across some odd behaviour usung MCLR with my program. Sometimes the program will not restart on the first MCLR reset, other times I can hit the switch 20+ times before this happens. A user would rarely use MCLR, but I would like it to be reliable. Once it does happen the program will not run again until a power on reset occurs. This occurs both with and without using a bootloader. MCLR still functions when this condition is present because if I pull up the bootloader entry pin, the bootloader will start after I again press the the MCLR switch. If I then remove the bootloader entry jumper and press MCLR, the program still will not run after the bootloader jumps to it.

This is running on a 18F14K50 with the following FC components: 2xADC, EEPROM, I2C, a momentary switch, 2 LEDs The main loop uses only the 2 ADCs, 1 LED and I2C. So these could be interrupted by the MCLR reset. Is there something that needs to be cleared on a restart that is not cleared on a MCLR reset? I have reviewed the datasheet and do not see an obvious cause. Seems to be I2C related as it does not hang if I disable the I2C stuff(DAC writes) in the main loop.

edit: Now I am thinking that this is because the I2C slaves are not also reset when the PIC is reset.

Regards,
Grant

GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

Re: Program randomly hangs on MCLR reset

Post by GTF »

Software control of power to the slaves fixed this. Another method might be to add some code to the I2C initialization to check for and clean up these I2C "stuck" situations.

edit: found this: http://www.analog.com/static/imported-f ... N686_0.pdf

GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

Re: Program randomly hangs on MCLR reset

Post by GTF »

Toggling the SCL pin until the SDA line is released by the slave also seems to do the trick. This is done prior to I2C initialization. This bit of code worked for me...... So I will be using both hardware and software methods.
Attachments
Clear_bus.JPG
(31.36 KiB) Downloaded 704 times

Post Reply