Reply
Posts: 4
Registered: ‎08-10-2017
Accepted Solution

BGM111 Wrong RTCC value in EM4H

Hi,

I'm trying to setup the RTCC (calendar) to work in EM4H mode. This is my setup code:

 

void rtccSetup(void)
{
  RTCC_Init_TypeDef rtccInit = RTCC_INIT_DEFAULT;

  /* Enable LFE domain for RTCC */
  CMU_ClockEnable(cmuClock_CORELE, true);
  CMU_ClockSelectSet(cmuClock_LFE, cmuSelect_LFXO);

  /* Enable RTC clock */
  CMU_ClockEnable(cmuClock_RTCC, true);

  /* In calendar mode, the pre-counter should be configured to give ticks with a period of   */
  /* one second, i.e. RTCC_CTRL_CNTTICK should be set to PRESC, and the CNTPRESC bitfield    */
  /* of the RTCC_CTRL register should be set to DIV32768 if a 32768 Hz clock source is used. */
  rtccInit.enable   = false;
  rtccInit.presc 	= rtccCntPresc_32768;
  rtccInit.cntMode 	= rtccCntModeCalendar;
  RTCC_Init(&rtccInit);

  /* Initialize date and time */
  if (!statusreg.bitv.EM4WAKEUP) {
	  RTCC_DateSet(START_DATE);
	  RTCC_TimeSet(START_TIME);

	  /* Start Counter */
	  RTCC_Enable(true);
  }
}

and here the main.c

 

int main(void)
{
	/* Funzione per abilitare l'advance energy monitor. Da togliere alla fine dello sviluppo */
	//BSP_TraceProfilerSetup();

	/* Funzione per l'attivazione dello SWO */
	BSP_TraceSwoSetup();

	rstcause = RMU_ResetCauseGet();
	RMU_ResetCauseClear();
	/* Avoid RTCC reset */
	RMU_ResetControl(rmuResetSys, rmuResetModeLimited);
	RMU_ResetControl(rmuResetPin, rmuResetModeLimited);

	statusreg.word = 0;
	if (rstcause & RMU_RSTCAUSE_EM4RST) {
		statusreg.bitv.EM4WAKEUP = 1;
		SWO_printf("Boot from EM4 reset\n");
	} else {
		SWO_printf("Default boot\n");
	}
	printf("RST cause: 0x%lx \n", rstcause);


	/* Initialize peripherals */
	enter_DefaultMode_from_RESET();

	/* Initialize stack */
	gecko_init(&config);

	/* RTCC */
	rtccSetup();

	/* Test LED */
	if (statusreg.bitv.EM4WAKEUP) {
		GPIO_PinOutClear(LED0_PORT, LED0_PIN);
	} else {
		GPIO_PinOutSet(LED0_PORT, LED0_PIN);
	}

  while (1) {
    /* Event pointer for handling events */
    struct gecko_cmd_packet* evt;
    
    // Check for stack event.
    evt = gecko_wait_event();
    // Run application and event handler.
    appBleHandleEvents(evt);
  }
}

 

last, my EM4 code:

 

void enterIntoEM4H(void)
{
	EMU_EM4Init_TypeDef em4Init = EMU_EM4INIT_DEFAULT;
    em4Init.retainLfxo = true;
    em4Init.pinRetentionMode = emuPinRetentionEm4Exit;
    em4Init.em4State = emuEM4Hibernate;
    EMU_EM4Init(&em4Init);

    RMU_ResetControl(rmuResetSys, rmuResetModeLimited);
    RMU_ResetControl(rmuResetPin, rmuResetModeLimited);

    SLEEP_ForceSleepInEM4();
}

 

RTCC work fine until BGM111 goes in EM4H. After wakeup I read the date and time but it's wrong like year '2001' and '82' seconds...

 

This is my init value:

RTCC Date: 0x4170810

RTCC Time: 0x103951

 

Here the value read after wakeup:

RTCC Date: 0x10810

RTCC Time: 0x10417c

 

What's wrong in my code?  Thank you.

 

Posts: 2,962
Registered: ‎08-25-2015

Re: BGM111 Wrong RTCC value in EM4H

Hi,

 

You can't use the RTCC in calendar mode. In fact you shouldn't really configured it to anything else other than what's shown in the examples as the Bluetooth stack relies on it for time keeping.

 

Regards,

Tiago

Posts: 4
Registered: ‎08-10-2017

Re: BGM111 Wrong RTCC value in EM4H

Thank you Tiago... I read on datasheet:

 

3.6.2 Real Time Counter and Calendar (RTCC)
The Real Time Counter and Calendar (RTCC) is a 32-bit counter providing timekeeping in all energy modes. The RTCC includes a
Binary Coded Decimal (BCD) calendar mode for easy time and date keeping.

 

So I presumed It's work... Without internat RTCC, I need to use an external device... or is there a way to implement an RTC in EM4H?

Highlighted
Posts: 2,962
Registered: ‎08-25-2015

Re: BGM111 Wrong RTCC value in EM4H

Hi,

 

You need to read UG136 to see what peripherals are reserved for the Bluetooth stack.

 

http://community.silabs.com/t5/Bluetooth-Wi-Fi-Knowledge-Base/Using-RTCC-as-Timer-or-Calendar-while-...

 

Regards,

Tiago