Embedded Systems, Microwaves, Software, Android Apps

Test

	uchar xdata buf[DATE_TIME_REG_SIZE];
	uchar xdata i;

	// check if Date/Time were previouly set
	GetEEByte( RTC_INITED(1), &i );
	if( i == (uchar)TRUE )
		RTCInited = TRUE;	// true unless some later check fails
	else
		RTCInited = FALSE;

	// initialize the DS3231:
	// - check the state of Oscillator Stop Flag to determine if time is good (OSF=1 -> bad, OSF=0 -> normal)
	if( !GetRTCByte( RTC_STATUS_ADDR, &buf[0] )){
		POBFault |= POB_FAULT_RTC;
		//Fault_Status[RTC_BATTERY_FAULT(1)] |= RTC_BATTERY_FAULT(0);
		RTCInited = FALSE;
		return( FALSE );
	}
	if( buf[0] & 0x80 ){
		// OSFD is set
		// if OSF is set, chip talks but time is bad, 
		// - clear OSF flaf
		// - enable oscillator
		// - turn off the square wave (to save power)
		// - turn off interrupt control
		// - disable alarms
		PutRTCByte( RTC_STATUS_ADDR, 0 );
		PutRTCByte( RTC_CONTROL_ADDR, 0 );
		Fault_Status[RTC_BATTERY_FAULT(1)] |= RTC_BATTERY_FAULT(0);
		PutEEByte( RTC_INITED(1), 0xFF );
		RTCInited = FALSE;
		InitEventLog();
	}