Hello
I am once again facing the Watchdog reset issue with k60 same way as i use to previously. I that time it worked but the same issue has cropped up once again and i dont understand the reason. while i refresh the watchdog and in debugging mode i am able to see it correctly refreshing it still resets. i have pasted my code here. Please someone have a look at it and help me out with the problem.
main.c and wdog.c files pasted
MAIN.c////////////////////////////////////////////
void main(void) {
disable_irq(45) ;
Init_Gpio();
gpio_init(PORTB, PTB, 1, OUTPUT); //Buzzer Output
// EnableInterrupts ;
wdog_init();
while(1) {
delay_wdog(10);
wdog_refresh();
/*
Vertical G calculation
*/
vertical_z_axis_g = z_axis_avg - 1000;
finalSendData[1] = vertical_z_axis_g/10;
/*
Lateral G calculation
*/
lateral_y_axis_g = y_axis_avg;
finalSendData[2] = lateral_y_axis_g/10;
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
WDOG.h
#include "wdog.h"
#include "common.h" // Common Kinetis defines
void wdog_init(void){
wdog_unlock();
WDOG_STCTRLH = WDOG_STCTRLH_DISTESTWDOG_MASK //Disable WDOG Test Mode
| WDOG_STCTRLH_ALLOWUPDATE_MASK | WDOG_STCTRLH_WDOGEN_MASK | WDOG_STCTRLH_CLKSRC_MASK ; //Allow WDOG CTRL Ref Update
WDOG_TOVALH = 0x0020;
WDOG_WINL = WDOG_WINH = 0;
WDOG_TOVALL = 0x5fff;
// WDOG_PRESC = WDOG_PRESC_PRESCVAL(7);
WDOG_STCTRLH &= ~(WDOG_STCTRLH_ALLOWUPDATE_MASK) ;
}
void wdog_refresh(void) {
DisableInterrupts;
WDOG_REFRESH = WDOG_REFRESH_WDOGREFRESH(WDOG_REFRESH_SEQUENCE_1);
WDOG_REFRESH = WDOG_REFRESH_WDOGREFRESH(WDOG_REFRESH_SEQUENCE_2);
EnableInterrupts;
}
void wdog_enable(void){
delay_wdog(60);
wdog_unlock();
delay_wdog(1);
WDOG_STCTRLH |= WDOG_STCTRLH_WDOGEN_MASK;
delay_wdog(20);
}
void wdog_unlock(void)
{
/* NOTE: DO NOT SINGLE STEP THROUGH THIS FUNCTION!!! */
/* There are timing requirements for the execution of the unlock. If
* you single step through the code you will cause the CPU to reset.
*/
/* This sequence must execute within 20 clock cycles, so disable
* interrupts will keep the code atomic and ensure the timing.
*/
DisableInterrupts;
/* Write 0xC520 to the unlock register */
WDOG_UNLOCK = 0xC520;
/* Followed by 0xD928 to complete the unlock */
WDOG_UNLOCK = 0xD928;
/* Re-enable interrupts now that we are done */
EnableInterrupts;
}
void wdog_set_timeout(uint32_t time) {
}
void delay_wdog(uint16_t nCount) {
uint16_t delay = 0;
for (delay=0;delay<nCount*10;delay++);
}
void wdog_disable(void)
{
/* First unlock the watchdog so that we can write to registers */
wdog_unlock();
/* Clear the WDOGEN bit to disable the watchdog */
WDOG_STCTRLH &= ~WDOG_STCTRLH_WDOGEN_MASK;
}