历史上的今天
今天是:2024年11月23日(星期六)
2019年11月23日 | mega328p watchdog 无效解决方案
2019-11-23 来源:51hei
以前一直用mega2560,好不容易解决了watchdog的问题,看门狗正常工作。
新项目中boss要求mega328p也能够支持看门狗,想想应该是比较容易的,毕竟avr官方文档中有对watchdog的说明。这个坑就这样埋下了。
写一个看门狗测试程序:
#include const int ledPin = 13; // the number of the LED pin void setup() { wdt_disable(); Serial.begin(9600); Serial.println("System Init OK!"); pinMode(ledPin, OUTPUT); Serial.println("Wait 5 Sec.."); delay(5000); wdt_enable(WDTO_8S); /* WDTO_15MS WDTO_30MS WDTO_60MS WDTO_120MS WDTO_250MS WDTO_500MS WDTO_1S WDTO_2S WDTO_4S WDTO_8S */ Serial.println("Watchdog enabled!"); } uint8_t timer = 0; void loop() { if (!(millis() % 1000)) { Serial.print(millis()); Serial.print("--"); timer++; Serial.println(timer); digitalWrite(ledPin, digitalRead(ledPin) == 1 ? 0 : 1); delay(1); } // wdt_reset(); } 第一次运转正常,成功复位,小case,随便就搞定了。However..... 复位之后居然就一直复位了...一直无限循环复位,像下面这样.... System Init OK! Wait 5 Sec.. Watchdog enabled! 5000--1 6000--2 7000--3 8000--4 9000--5 10000--6 11000--7 12000--8 13000--9 System Init OK! 我去,这怎么回事。猜测可能是bootloader的问题,搞个optiboot来看看,听说对watchdog支持十分良好。 烧录上之后,依然这个问题。 解决方案:http://www.nongnu.org/avr-libc/u ... _avr__watchdog.html 这里的说明: Note that for newer devices (ATmega88 and newer, effectively any AVR that has the option to also generate interrupts), the watchdog timer remains active even after a system reset (except a power-on condition), using the fastest prescaler value (approximately 15 ms). It is therefore required to turn off the watchdog early during program startup, the datasheet recommends a sequence like the following: 对于atmega88以及新型号的单片机(自带产生中断的),看门狗可能会在系统复位之后,依然运行(除掉电复位外)。因此,需要在程序启动早期,关闭看门狗。datasheet中推荐插入一段这样的程序: #include #include uint8_t mcusr_mirror __attribute__ ((section (".noinit"))); void get_mcusr(void) __attribute__((naked)) __attribute__((section(".init3"))); void get_mcusr(void) { mcusr_mirror = MCUSR; MCUSR = 0; wdt_disable(); } 然后,问题解决,正常复位.. 还是的多看datasheet..哎
史海拾趣
|
本帖最后由 paulhyde 于 2014-9-15 09:03 编辑 得到的09年电子大赛西电的材料清单,看清单可以猜到部分题目,希望对大家猜题有帮助。 既然大家都普遍觉得贵 我就免费发送吧。希望对统一战线的同志们有帮助! [ 本帖最后由 五月一 于 2009-8-23 ...… 查看全部问答> |
|
一个女生用C语言写的爱情函数result love(boy, girl) { if ( boy.有房() and boy.有车() ) { boy.set(nothing); ...… 查看全部问答> |
|
大家好,正在做一个项目,通信芯片接收区FIFO大小为8word,数据收发通过调用一个函数完成,每次接收一个字节,通过调试发现,当一包数据大小在13、14个字节以内时,收发正常。现在需要通过串口做大数据量的收发,每包数据都在1000字节以上,因为我 ...… 查看全部问答> |
|
在WINCE下的触摸屏的校正程序中,我是直接调用的这个系统函数TouchCalibrate,呵呵……自己还没有想到写的方法。但是没有这个的源码,在TouchCalibrateUI_DrawMainScreen打印校准操作说明信息中,UseEnterEsc这个函数是怎么操作的?在屏幕我要显示 ...… 查看全部问答> |
|
想好好学学STM32F4,想淘一个或者置换一个F4的板子我有的板子:LM3s811和8962的板子(原装的未开封),这两个板子是我用无线wifi路由器和一位兄弟换来的。avr和MSP430的板子也各有一个,… 查看全部问答> |




