Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't enable TIM2 capture compare interruption #2

Open
ilyamordasov opened this issue Sep 28, 2020 · 0 comments
Open

Can't enable TIM2 capture compare interruption #2

ilyamordasov opened this issue Sep 28, 2020 · 0 comments

Comments

@ilyamordasov
Copy link

I wanna get the signal in transparent mode, for that I use TIM2_CH2 for input capture, however I can't call interrupt.

I added irq handler into main.c

ISR_TIM2_CC(TIM2_CAP_COM) {
    printf("/\r\n");
    if (TIM2_SR1 & 0x04) { // interrupt on rising edge
        if (!flag){
            flag = true;
            pulse_width = 0;
            TIM2_SR1 = 0;
        }
        else {
            flag = false;
            period = ((TIM2_CCR2L | (TIM2_CCR2H << 8)) - period);
            if (period > 200) { // check if it's not a preamble
                code = (code << 1) | (pulse_width < period/2) ? 1 : 0;
                period = 0;
                TIM2_CCR2H = 0;
                TIM2_CCR2L = 0;
                counter++;
            }
            else {
                preamble = (preamble << 1) | 1;
            }
        }
        
        if (TIM2_SR2) { // overcapture
            TIM2_SR2 = 0;
        }
    }
    if (TIM2_SR1 & 0x02) { // interrupt on falling edge
        pulse_width = TIM2_CCR2L | (TIM2_CCR2H << 8);
        if (counter >= 60) {
            printf("Preamble: 0x%x\r\n", preamble);
            printf("Code: 0x%x\r\n", code);
            counter = 0;
        }
    }
}

But even I can't display printf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant