Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Issue with external RTC mcp9941x alarms

Status
Not open for further replies.

krishkrishna

Newbie level 3
Newbie level 3
Joined
Mar 24, 2014
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
39
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............
 

Can you wrap this as code rather then text?

Some more information:
1.) Circuit setup
2.) Interrupt setup (I see that is called but I don't see where you do this at)
3.) Address definitions
 

Re: Issue with external RTC mcp7941x alarms

Can you wrap this as code rather then text?

Some more information:
1.) Circuit setup
2.) Interrupt setup (I see that is called but I don't see where you do this at)
3.) Address definitions

Hi..greg

Here is my ISR and Address definitions...

Code:
void RTCINTInit(void)
{
    PORTSetPinsDigitalIn(IOPORT_E, BIT_9);
    INTCONSET = 0x00000002;
    INTSetVectorPriority(INT_EXTERNAL_2_VECTOR, INT_PRIORITY_LEVEL_3);
    INTSetVectorSubPriority(INT_EXTERNAL_2_VECTOR, INT_SUB_PRIORITY_LEVEL_1);
    INTEnable(INT_INT2, INT_ENABLED);
}
================================================================
     #define  ADDR_EEPROM_WRITE 0xae       //  DEVICE ADDR for EEPROM (writes)
     #define  ADDR_EEPROM_READ  0xaf       //  DEVICE ADDR for EEPROM (reads)
     #define  ADDR_RTCC_WRITE   0xde       //  DEVICE ADDR for RTCC MCHP  (writes)
     #define  ADDR_RTCC_READ    0xdf       //  DEVICE ADDR for RTCC MCHP  (reads)
//.................................................................................
     #define  SRAM_PTR          0x20       //  pointer of the SRAM area (RTCC)
     #define  ADDR_EEPROM_SR    0xff       //  STATUS REGISTER in the  EEPROM
//.................................................................................
     #define  ADDR_SEC          0x00       //  address of SECONDS      register
     #define  ADDR_MIN          0x01       //  address of MINUTES      register
     #define  ADDR_HOUR         0x02       //  address of HOURS        register
     #define  ADDR_DAY          0x03       //  address of DAY OF WK    register
     #define  ADDR_STAT         0x03       //  address of STATUS       register
     #define  ADDR_DATE         0x04       //  address of DATE         register
     #define  ADDR_MNTH         0x05       //  address of MONTH        register
     #define  ADDR_YEAR         0x06       //  address of YEAR         register
     #define  ADDR_CTRL         0x07       //  address of CONTROL      register
     #define  ADDR_CAL          0x08       //  address of CALIB        register
     #define  ADDR_ULID         0x09       //  address of UNLOCK ID    register
//.................................................................................
     #define  ADDR_ALM0SEC      0x0a       //  address of ALARMO SEC   register
     #define  ADDR_ALM0MIN      0x0b       //  address of ALARMO MIN   register
     #define  ADDR_ALM0HR       0x0c       //  address of ALARMO HOUR  register
     #define  ADDR_ALM0CTL      0x0d       //  address of ALARM0 CONTR register
     #define  ADDR_ALM0DAT      0x0e       //  address of ALARMO DATE  register
     #define  ADDR_ALM0MTH      0x0f       //  address of ALARMO MONTH register
//.................................................................................
     #define  ADDR_ALM1SEC      0x11       //  address of ALARM1 SEC   register
     #define  ADDR_ALM1MIN      0x12       //  address of ALARM1 MIN   register
     #define  ADDR_ALM1HR       0x13       //  address of ALARM1 HOUR  register
     #define  ADDR_ALM1CTL      0x14       //  address of ALARM1 CONTR register
     #define  ADDR_ALM1DAT      0x15       //  address of ALARM1 DATE  register
     #define  ADDR_ALM1MTH      0x16       //  address of ALARM1 MONTH register
//.................................................................................
     #define  ADDR_SAVtoBAT_MIN 0x18       //  address of T_SAVER MIN(VDD->BAT)
     #define  ADDR_SAVtoBAT_HR  0x19       //  address of T_SAVER HR (VDD->BAT)
     #define  ADDR_SAVtoBAT_DAT 0x1a       //  address of T_SAVER DAT(VDD->BAT)
     #define  ADDR_SAVtoBAT_MTH 0x1b       //  address of T_SAVER MTH(VDD->BAT)
//..................................................................................
     #define  ADDR_SAVtoVDD_MIN 0x1c       //  address of T_SAVER MIN(BAT->VDD)
     #define  ADDR_SAVtoVDD_HR  0x1d       //  address of T_SAVER HR (BAT->VDD)
     #define  ADDR_SAVtoVDD_DAT 0x1e       //  address of T_SAVER DAT(BAT->VDD)
     #define  ADDR_SAVtoVDD_MTH 0x1f       //  address of T_SAVER MTH(BAT->VDD)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//                  GLOBAL CONSTANTS RTCC - INITIALIZATION
//..................................................................................
     #define  START_32KHZ  0x80            //  start crystal: ST = b7 (ADDR_SEC)
     #define  LP           0x20            //  mask for the leap year bit(MONTH REG)
     #define  HOUR_12      0x40            //  12 hours format   (ADDR_HOUR)
     #define  PM           0x20            //  post-meridian bit (ADDR_HOUR)
     #define  OUT_PIN      0x80            //  = b7 (ADDR_CTRL)
     #define  SQWE         0x40            //  SQWE = b6 (ADDR_CTRL)
     #define  ALM_NO       0x00            //  no alarm activated        (ADDR_CTRL)
     #define  ALM_0        0x10            //  ALARM0 is       activated (ADDR_CTRL)
     #define  ALM_1        0x20            //  ALARM1 is       activated (ADDR_CTRL)
     #define  ALM_01       0x30            //  both alarms are activated (ADDR_CTRL)
     #define  MFP_01H      0x00            //  MFP = SQVAW(01 HERZ)      (ADDR_CTRL)
     #define  MFP_04K      0x01            //  MFP = SQVAW(04 KHZ)       (ADDR_CTRL)
     #define  MFP_08K      0x02            //  MFP = SQVAW(08 KHZ)       (ADDR_CTRL)
     #define  MFP_32K      0x03            //  MFP = SQVAW(32 KHZ)       (ADDR_CTRL)
     #define  MFP_64H      0x04            //  MFP = SQVAW(64 HERZ)      (ADDR_CTRL)
     #define  ALMx_POL     0x00            //  polarity of MFP on alarm  (ADDR_ALMxCTL)
     #define  ALMxC_SEC    0x00            //  ALARM compare on SEC      (ADDR_ALMxCTL)
     #define  ALMxC_MIN    0x10            //  ALARM compare on MIN      (ADDR_ALMxCTL)
     #define  ALMxC_HR     0x20            //  ALARM compare on HOUR     (ADDR_ALMxCTL)
     #define  ALMxC_DAY    0x30            //  ALARM compare on DAY      (ADDR_ALMxCTL)
     #define  ALMxC_DAT    0x40            //  ALARM compare on DATE     (ADDR_ALMxCTL)
     #define  ALMxC_ALL    0x70            //  ALARM compare on all param(ADDR_ALMxCTL)
     #define  ALMx_IF      0x08            //  MASK of the ALARM_IF      (ADDR_ALMxCTL)
     #define  OSCON        0x20            //  state of the oscillator(running or not)
     #define  VBATEN       0x08            //  enable battery for back-up
And Regarding circuit set up..
2.2k pull ups is been connected to my SCL and SDA lines.
and 10k Pullup is connected to my external interrupt pin...
And my RTC clock is 100 KHz.
 
Last edited:

Re: Issue with external RTC mcp7941x alarms

Kindly Let me know guys. If is there any mistake in my code..or my interrupt set up.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top