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:
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
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 ();
}
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