Hello everybody,
I'd a bit confused with the RTC_B module, and I'd like some assistance to understand how it works.
This is what i got so far:
- Let's say we got the RTC_B running somehow when Power was available for the MSP430.
- Once power fades, the backup system comes into play, keeping the counters + Oscillator LFXT1 running.
The configuration registers are lost, but the RTC keeps working....
- Once power is present again : code starts, lockbak bit locks the registers of the RTC so the informations wont get overwritten ? because I read "The LOCKBAK bit should only be written as 0 after configuring the RTC control
registers."
Now TO test the RTC on my custom Board, I made this code:
#include "driverlib.h" Calendar time; int main(void) { WDT_A_hold(WDT_A_BASE); // erase LOCKBAK bit time.DayOfMonth = 17; time.DayOfWeek = 06; time.Hours = 23; time.Minutes = 59; time.Seconds = 55; time.Year = 2015; GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5); GPIO_setAsOutputPin(GPIO_PORT_P5, GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5); GPIO_setAsInputPinWithPullDownResistor(GPIO_PORT_P1, GPIO_PIN6); __delay_cycles(1000000); if (GPIO_getInputPinValue(GPIO_PORT_P1, GPIO_PIN6)) { GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3 + GPIO_PIN5); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN4); RTC_B_initCalendar(RTC_B_BASE, &time, RTC_B_FORMAT_BINARY); BAK_BATT_unlockBackupSubSystem(BAK_BATT_BASE); __delay_cycles(1000000); GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5); } BAK_BATT_unlockBackupSubSystem(BAK_BATT_BASE); RTC_B_startClock(RTC_B_BASE); while (1) { time = RTC_B_getCalendarTime(RTC_B_BASE); if (time.DayOfMonth > 17) { GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN4 + GPIO_PIN5); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN3); } else if (time.DayOfMonth == 0) { GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3 + GPIO_PIN4); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN5); } else { GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3 + GPIO_PIN5); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN4); } } }
When the press button is pressed at start: reset clock to January 17th 5 seconds before midnight.
else, just keep clock running.
This works only if I
BAK_BATT_unlockBackupSubSystem(BAK_BATT_BASE); first
then
RTC_B_initCalendar(RTC_B_BASE, &time, RTC_B_FORMAT_BINARY);
which is contradictory to the information in the Family Guide ?
What makes me even more confused, even after reading a very similar thread, is the SVSH reset story...
IS teh purpose of that to check that there is sufficient DVCC before erasing LOKBAK bit otherwise keep sourcing RTC from bakup battery ?
Help would be much appreciated.
Thanks
Ness