Wh1teRabbitHU / DCF77-Driver

DCF77 driver, written in C. Primarily made for STM32, but it can be also used with any other MCU-s.
GNU General Public License v3.0
2 stars 2 forks source link

Help Wanted #1

Open annaFurlan opened 1 month ago

annaFurlan commented 1 month ago

hi, I can't get your DCF77 library to work corectually, from your description I can't exactly understand in which interrupt I should put the function “void DCF77_handleInterrupt(uint32_t currentTick, uint8_t pinState)”. Can I ask you to give an example of how to use the DCF77 library?

Thanks a lot in advance Anna

Wh1teRabbitHU commented 1 month ago

Hey Anna!

Sorry for the late reply, Github still doesn't send me notifications -_- Interrupt in this case is when the signal from your antenna changes state (going from low to high or high to low) Depends on what you use, you should have hardware supported interrupts.

If you use STM MCU, you need this: https://wiki.st.com/stm32mcu/wiki/Getting_started_with_EXTI If you use Arduino, you need this: https://roboticsbackend.com/arduino-interrupts/

I explain it with the Arduino example, my guess is that you have that

#include "dcf77-driver.h"

#define ANTENNA_PIN 3

static DCF77_dateTime_t* currentTime;

void handleDCF77Interrupt() {
    uint32_t tick = millis();
    uint8_t pinState = digitalRead(ANTENNA_PIN);

    DCF77_handleInterrupt(tick, pinState);
}

void setup() {
    pinMode(ANTENNA_PIN, INPUT);

    attachInterrupt(digitalPinToInterrupt(ANTENNA_PIN), handleDCF77Interrupt, CHANGE);

    DCF77_enable();
}

void loop() {
    if (DCF77_timeReceived()) {
        currentTime = DCF77_lastTimeValue();  // You get your time, yey
        DCF77_reset();

        // After this, you can use the time to show on some display
    }

    delay(100);
}

Keep in mind that even if the code works, it's important that your antenna stays stable and pointed to the right direction. It's a bit tricky to make it work, but you can debug the interrupt signal by printing out the changes in the handleDCF77Interrupt function.

Let me know if you managed to make it work and I close this ticket!