Closed
Description
/* The following code does not behave as expected due to:
Default test case: No default ISR, or some other ISR related failure
Interrupt & Serial test case: Some timer interrupt & serial interrupt conflict
Some of these may simply be non-intuitive results
from the default programming conditions, but others are clearly bugs.
Test cases are marked with "***" preceeding and following,
and can be enabled by disabling the preceeding "/*". Please correct all issues. */
/* This was tested on a Sparkfun 3.3v Arduino Pro Mini with the Arduino 1.0.2 IDE. */
#define T1CRA 0b00000011 // COM1A = 0, COM1B = 0, WGM[1:0] = 3;
#define T1CRB 0b00011101 // FOC1A = 0, FOC1B = 0, WGM[3:2] = 3, CS1 = 5;
void setup()
{
// Disable the Interrupts.
noInterrupts();
Serial.begin(9600);
// Configure the Timer. WGM = 7, which tops out at OCR1A.
TCCR1A = T1CRA;
TCCR1B = T1CRB;
OCR1A = 250;
TCNT1 = 0;
// valid */ valid
/*
// This byte disables timer interrupts.
TIMSK1 = 0b00000000; // *** Disable this interrupt enable bit to work around the bug. ***
// *** Re-enable before performing the tests that follow. ***
// This byte enables timer interrupts.
// */ TIMSK1 = 0b00000010; // *** Disable this interrupt enable bit to work around the bug. ***
// *** Re-enable before performing the tests that follow. *** */
// Initialize pins
pinMode(13, OUTPUT);
// Reenable the Interrupts.
interrupts();
}
/* // *** Disable again before performing the tests that follow. ***
ISR(TIMER1_COMPA_vect) {} // *** Re-enabling an empty vector also works around the bug. *** */
/* // *** Disable again before performing the tests that follow. ***
ISR(TIMER1_COMPA_vect) // *** Valid non-serial code also works around the bug. ***
{
digitalWrite(13, !digitalRead(13));
}
//*/
/* // *** Keep enabled for the following test. ***
ISR(TIMER1_COMPA_vect) // *** Serial code in an interrupt seems to cause occasional problems. ***
{
Serial.println("Blaaarg???");
// Serial.flush(); // *** Adding flush seems to grind my Arduino to a halt. ***
}
//*/
void loop()
{
Serial.println("Blarg!");
Serial.flush();
}
Metadata
Metadata
Assignees
Labels
No labels