Setting the alarm on rtc

Hi,
I'm trying to understand how a repetive alarm every 40th second is set for the rtc AB1805
Attached is the piece of code in my library I have so far. Unfortunatly it didn't work.
Can somebody help me to find the mistake?

The manufacturer of the rtc writes:

The AB18X5 may be configured to generate the AIRQ interrupt when the 
values in the Time and Date Registers match the values in the Alarm 
Registers. Which register comparisons are required to generate AIRQ is 
controlled by the RPT field as described in the Repeat Function table, 
allowing software to specify the interrupt interval. When an Alarm 
Interrupt is generated, the ALM flag is set and an external interrupt is 
generated based on the AIE bit and the pin configuration settings. The 
IM field controls the period of the external interrupt, including both 
level and pulse configurations.
#define TIMER_CONTROL_RPT_ONCE_PER_SECOND     7
#define TIMER_CONTROL_REGISTER      0x18
#define TIMER_CONTROL_RPT_MASK 0x1C


void AB1805::set_once_second_alarm(uint8_t hundredths)
{
    set_second_alarm(hundredths);
    set_RPT_time_control(TIMER_CONTROL_RPT_ONCE_PER_SECOND);
}

bool AB1805::set_second_alarm(uint8_t value) {
    _alarm_second = value % MAX_SECOND;
    write_rtc_register(SECOND_ALARM_REGISTER,dec2hex(_alarm_second));
    _alarm_second = get_second_alarm();
    return (value == _alarm_second);
}

uint8_t AB1805::set_RPT_time_control(uint8_t value)
{
  uint8_t c1;
  c1 = read_rtc_register(TIMER_CONTROL_REGISTER);
  c1 &= ~TIMER_CONTROL_RPT_MASK;
  c1 |= (value << 2) & TIMER_CONTROL_RPT_MASK;
  write_rtc_register(TIMER_CONTROL_REGISTER,c1);
  return c1;
}

unsigned char AB1805::dec2hex(unsigned char val)
{
	val = val + 6 * (val / 10);
	return val;
}

You don't mention it in your post but I assume that you have got the RTC running and you can communicate with it over I2C to set and read the basic time?

I would imagine that you need to configure the repeat alarm to match hundredths and seconds (RPT=6) in the Countdown Timer Control Register, and that you would set the hundredths alarm to zero and the seconds alarm to 40. Also set the AIE bit in the Interrupt Mask Register (and IM bits to 00).

It looks like the FOUT pin is where the interrupt signal appears. You need a pull-up resistor on this pin for correct interrupt operation.

You could also poll the ALM bit in the Status Register to see if it ever gets set as this would bypass the whole external interrupt mechanism on the RTC and your micro, just to see if you have the alarm setup correctly.

Dear mark

yes the general communication via i2c is working, time etc is set and read correct.
There are also pull-up resistors installed(I had it in my mind writing it but forgot-sry)

Also set the AIE bit in the Interrupt Mask Register (and IM bits to 00).
Do you mean set those two bits or really 00?

I have set them at the moment (0x3 <<5)

edit:
i don't know exactly what I did but got now that signal on the picture on the fout-output. Even when restarting the mcu the signal appears straight away

From your scope screenshot, it looks like you have a horizontal scale of 1.2sec/div. There's obviously a constant stream of interrupts coming out of the RTC. With both IM bits set, the datasheet says that the interrupt signal will go low for 1/4sec which is what you appear to have. It also looks like you are getting 8 interrupts in 6 seconds. That's obviously not one every 60sec (at the 40th second of the minute).

Another thought, and possibly unrelated, but your earlier code was calling a dec2hex() function to convert the value for the alarm register. This should be a dec2bcd() conversion as the RTC used the BCD number representation.

I found the issue.. it was this part

TIMER_CONTROL_RPT_ONCE_PER_SECOND

which I changed now to

TIMER_CONTROL_RPT_ONCE_PER_MINUTE

what has the value 6 and it's working now.
Thanks for pointing me to the hex thing, I changed it now as well

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.