本帖最后由 手机早晚报 于 2016-9-30 22:54 编辑
[mw_shl_code=c,true]#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "lcd.h"
#include "adc.h"
#include "wwdg.h"
int main(void)
{
u16 adcx;
float temp;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
delay_init(168);
uart_init(115200);
LED_Init();
LCD_Init();
Adc_Init();
KEY_Init();
WWDG_Init(0x7f,0x50,WWDG_Prescaler_8);
POINT_COLOR=RED;
LCD_ShowString(30,50,200,16,16,"Explorer STM32F4");
LCD_ShowString(30,70,200,16,16,"ADC TEST");
LCD_ShowString(30,90,200,16,16,"ATOM@ALIENTEK");
LCD_ShowString(30,110,200,16,16,"2014/5/6");
POINT_COLOR=BLUE;
LCD_ShowString(30,130,200,16,16,"ADC1_CH5_VAL:");
LCD_ShowString(30,150,200,16,16,"ADC1_CH5_VOL:0.000V");
SWITCH=1;
while(1)
{
adcx=Get_Adc_Average(ADC_Channel_5,20);
LCD_ShowxNum(134,130,adcx,4,16,0);
temp=(float)adcx*(3.08/4096);
adcx=temp;
LCD_ShowxNum(134,150,adcx,1,16,0);
temp-=adcx;
temp*=1000;
LCD_ShowxNum(150,150,temp,3,16,0X80);
delay_ms(250);
}
}
[/mw_shl_code][mw_shl_code=c,true]#include "wwdg.h"
u8 WWDG_CNT=0X7F;
void WWDG_Init(u8 tr,u8 wr,u32 fprer)
{
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG,ENABLE);
WWDG_CNT=tr&WWDG_CNT;
WWDG_SetPrescaler(fprer);
WWDG_SetWindowValue(wr);
WWDG_SetCounter(WWDG_CNT);
WWDG_Enable(WWDG_CNT);
NVIC_InitStructure.NVIC_IRQChannel=WWDG_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x02;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0x03;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
WWDG_ClearFlag();
WWDG_EnableIT();
}
void WWDG_IRQHandler(void)
{
WWDG_SetCounter(WWDG_CNT);
WWDG_ClearFlag();
}
[/mw_shl_code]
这个窗口看门狗, 在主函数中的wwdg初始化WWDG_Init(0x7f,0x50,WWDG_Prescaler_8);,,现在这个程序只有窗口值与T[6:0]>=计数器值时,才正常;只要窗口值比计数器值小,程序就不断复位, ,问题就在于wwdg初始化时:只要tr>wr,就不断重启;令tr<=wr,就不会重启
但是按照手册,0x40<tr<0x7f,0x40<wr<0x7f,两个并无大小的比较
这个工程是在原子的adc实验库函数工程里直接添加wwdg的文件
我今晚以解决,在wwdg的中断服务函数中,在喂狗的语句前,加了一句判断if((WWDG->CR&0x7F)==0x40)
解决了wwdg在初始化时,中断标志位被置1,而进中断喂狗(此时计数值就在窗口之上,喂狗必定导致复位)
加了这句语句后,wwdg初始化函数中“WWDG_EnableIT();”与“WWDG_Enable(WWDG_CNT);”的顺序就可以随意呼唤
至于为什么开启中断时,EWIF中断标记位会被置1,我也不清楚
一周热门 更多>