Skip to content

Problem in sysclock_init_interrupt() on ATmega328 #1

Description

@bithive

I had to replace the first four lines:

TCCR2A |= (1<<CS22); 
TCCR2A &= ~((1<<CS21) | (1<<CS20));  
TCCR2A &= ~((1<<WGM21) | (1<<WGM20)); 
TCCR2B = 0x03;		// divide by 32 

With this:

TCCR2A |= ((1<<WGM21) | (1<<WGM20));
TCCR2B |= ((1<<CS21) | (1<<CS20));
TCCR2B &= ~(1<<CS22);

To get libtask working on my Arduino Pro Mini. I think the original code only works on the Mega2560? Just thought I'd post in case anyone else runs into the same problem. Symptom was garbage serial output.

Edit: Actually it seems like adding #include <avr/interrupt.h> in sysclock.cpp fixes the issue. I had included Arduino.h which also includes that file and tried the original code again on a hunch. Both versions of the code above now appear to work in that my serial output and blink tasks work, so long as I include either Arduino.h or avr/interrupt.h.

I picked my flags based on my understanding of the timer2 section on https://sites.google.com/site/qeewiki/books/avr-guide/timers-on-the-atmega328 but I don't really know what I'm doing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions