Lattice large-screen speech sensor--ds3231 high-precision clock module

Source: Internet
Author: User

DS3231 high-precision clock module is cheap and easy to use, SDA/SCL two IO ports can handle the basic functions, but when using the alarm interrupt output encountered a problem, that is, the alarm interrupt will only output once, and then always keep low level.

This problem data sheet does not explicitly, in the online search for a long time, a little information has not been found, had to toss themselves.

After repeated attempts, the final confirmation that the DS3231 alarm interrupt output is correctly used as follows:

    • First is initialization, setting alarm time and allowing interrupt output

void Ds3231_init_alarm2 () {
I2c_start ();
I2c_putbyte (Ds3231_write);
I2c_putbyte (Ds3231_control);
I2c_putbyte (0x0); Intcn=1,a2ie=1,enable interrupts, Alarm 2 output
I2c_putbyte (0x0);
I2c_stop ();

    I2c_start ()    
    i2c_putbyte (ds3231_write);    
& nbsp;      I2c_putbyte (Ds3231_alarm2minute);    
    i2c_putbyte (0x0);       //min, a2m2=0   & nbsp
    i2c_putbyte (0x80);       //, a2m3=1    
    i2c_putbyte (0x80);       //a2m4=1,dy=0    
    i2c_stop ();

I2c_start ();
I2c_putbyte (Ds3231_write);
I2c_putbyte (Ds3231_control);
I2c_putbyte (0x06); Intcn=1,a2ie=1,enable interrupts, Alarm 2 output
I2c_putbyte (0x0);
I2c_stop ();
}

I'm using the alarm 2, the hourly output is interrupted

    • To turn off the corresponding alarm interrupt output (a2ie=0) After the interrupt is triggered

void Perhour_extint1 () interrupt 2 using 1 {
EX1 = 0;
Ds3231_disable_alarm2 ();

......
}

void Ds3231_disable_alarm2 ()
{
I2c_start ();
I2c_putbyte (Ds3231_write);
I2c_putbyte (Ds3231_control);
I2c_putbyte (0x4); Intcn=1,a2ie=0,
I2c_putbyte (0x0);
I2c_stop ();
}

    • Re-initialize the alarm at the appropriate time

This is important when it is right, and if it is reinitialized immediately, the interrupt condition is still met and the interrupt continues to trigger, which will cause the next alarm to expire. In other words, at least 1 seconds later, I was re-initialized before the microcontroller entered power-down mode.

This article from "Tsing Lung Yan Yue" blog, reproduced please contact the author!

Lattice large-screen speech sensor--ds3231 high-precision clock module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.