Hi..Guys...
I am trying to make use of both rtc alarms(alarm0 & alarm1) of mcp7941x chip.
But i am seeing one problem if enable both the alarms that is when i get the ALM0IF(alarm1 interrupt flag) flag set at that time ALM1IF(alarm1 interrupt flag) also getting set.without alarm1 match condtion.
Let's say my alarm 0 & alarm1 match condition is based on minutes and my ALM0 is for 2 mins and ALM1 is for 5 mins then when ALM0 match occurs i am seeing both flags getting set.
Can anybody help me out this.
And here the code i am using for alarm config and set alm time.
void config alarm()
{
SetALM0Time();
DelayMs(2);
SetALM1Time();
DelayMs(2);
RTCINTInit();//enabling rtc interrupt
DelayMs(2);
}
void SetALM0Time(void)
{
unsigned int temp;
WriteAddress[0] = RTC_WRITE_ADDR;
temp = ReadOnI2C(ADDR_ALM0CTL);
temp = temp & 0xF0;
DelayMs(2);
WriteOnI2C(ADDR_ALM0CTL, uint2bcd(temp));
DelayMs(2);
RdRTC(&TStatus);
DelayMs(2);
WriteOnI2C(ADDR_ALM0MTH, uint2bcd(TStatus.MONTH));
DelayMs(2);
WriteOnI2C(ADDR_ALM0DAT, uint2bcd(TStatus.DATE));
DelayMs(2);
temp = TStatus.MIN + AL0_TASKDURATION;
if(temp >= 60)
{
temp -= 60;
WriteOnI2C(ADDR_ALM0MIN, uint2bcd(temp));
DelayMs(2);
if(TStatus.HOUR == 23)
WriteOnI2C(ADDR_ALM0HR, 0);
else
WriteOnI2C(ADDR_ALM0HR, uint2bcd(TStatus.HOUR + 1));
}
else
{
WriteOnI2C(ADDR_ALM0MIN, uint2bcd(TStatus.MIN + AL0_TASKDURATION));
DelayMs(2);
WriteOnI2C(ADDR_ALM0HR, uint2bcd(TStatus.HOUR));
}
DelayMs(2);
WriteOnI2C(ADDR_ALM0SEC, uint2bcd(TStatus.SEC));
DelayMs(2);
WriteOnI2C(ADDR_ALM0CTL, ALMx_POL + ALMxC_MIN);
DelayMs(2);
// WriteOnI2C(ADDR_CTRL, ALM_01); //Enable ALM01
// DelayMs(2);
}
void SetALM1Time(void)
{
unsigned int temp1;
WriteAddress[0] = RTC_WRITE_ADDR;
temp1 = ReadOnI2C(ADDR_ALM1CTL);
temp1 = temp1 & 0xF0;
DelayMs(2);
WriteOnI2C(ADDR_ALM1CTL, uint2bcd(temp1));
DelayMs(2);
RdRTC(&TStatus);
DelayMs(2);
WriteOnI2C(ADDR_ALM1MTH, uint2bcd(TStatus.MONTH));
DelayMs(2);
WriteOnI2C(ADDR_ALM1DAT, uint2bcd(TStatus.DATE));
DelayMs(2);
temp1 = TStatus.MIN + AL1_TASKDURATION;
if(temp1 >= 60)
{
temp1 -= 60;
WriteOnI2C(ADDR_ALM1MIN, uint2bcd(temp1));
DelayMs(2);
if(TStatus.HOUR == 23)
WriteOnI2C(ADDR_ALM1HR, 0);
else
WriteOnI2C(ADDR_ALM1HR, uint2bcd(TStatus.HOUR + 1));
}
else
{
WriteOnI2C(ADDR_ALM1MIN, uint2bcd(TStatus.MIN + AL1_TASKDURATION));
DelayMs(2);
WriteOnI2C(ADDR_ALM1HR, uint2bcd(TStatus.HOUR));
}
DelayMs(2);
WriteOnI2C(ADDR_ALM1SEC, uint2bcd(TStatus.SEC));
DelayMs(2);
WriteOnI2C(ADDR_ALM1CTL, ALMx_POL + ALMxC_MIN);
DelayMs(2);
WriteOnI2C(ADDR_CTRL, ALM_01);
DelayMs(2);
}
i would be very Grateful to you if anyone help me............