下面程序的目的是定期在串行上输出一个数据帧。该周期由每秒一次的定时中断定义。
该代码在 Arduino IDE 版本 0022 上工作,但在 1.0 上我无法让它工作。当使用定时器例程并maxFrameLength
设置为0x40
或更高时,控制器锁定。使用 0x39 或更低时,程序继续运行(由闪烁的 LED 指示)。
这里出了什么问题,为什么?它是一个错误吗?难道我做错了什么?
我在Mega1280 上使用http://code.google.com/p/arduino-timerone/downloads/detail?name=TimerOne-v9.zip作为定时器例程。
#include "TimerOne.h"
#define LED 13
#define maxFrameLength 0x40
boolean stateLED = true;
byte frame[ maxFrameLength ];
void sendFrame() {
digitalWrite( LED , stateLED );
stateLED = !stateLED;
Serial.write( frame, maxFrameLength ); // ptr + bytes to send
}
void setup() {
pinMode( LED , OUTPUT );
Timer1.initialize( 1000000 ); // initialize timer1 with 1 second period
Timer1.attachInterrupt( sendFrame );
Serial.begin( 9600 );
};
void loop() {
};