/*******************************************************************main.c*********************************************************************************************************/
/************************************************************************
* @file main.c
* @author Mr.Blue
* @version V1.0
* @date 2015-6-16
* @brief This file provides functions to manage the functionalities
* of the IIC
* @verbatim
************************************************************************/
/******************************INCLUDE**********************************/
#include "MSP430F5529_conf.h"
#include "Delay.h"
#include "IIC_device.h"
/******************************DEFINE***********************************/
#define UCS_MCLK_DESIRED_FREQUENCY_IN_KHZ 24000
//Target frequency for MCLK in kHz
#define UCS_MCLK_FLLREF_RATIO 6
//MCLK/FLLRef Ratio
#define UCS_XT1_TIMEOUT 50000
//Desired Timeout for XT1 initialization
#define UCS_XT2_TIMEOUT 50000
//Desired Timeout for XT2 initialization
#define IIC_SLAVE_ADDRESS 0X50
void UCS_init();
void GPIO_init();
/*****************************VARIABLE**********************************/
u16 status;
//Variable to store status of Oscillator fault flags
//Select XT1 as ACLK source
UCS_initClockSignal(UCS_ACLK,UCS_XT1CLK_SELECT,UCS_CLOCK_DIVIDER_1);
//Select XT2 as FLL reference
UCS_initClockSignal(UCS_FLLREF,UCS_XT2CLK_SELECT,UCS_CLOCK_DIVIDER_1);
//Set Ratio and Desired MCLK Frequency and initialize DCO
UCS_initFLLSettle(UCS_MCLK_DESIRED_FREQUENCY_IN_KHZ,UCS_MCLK_FLLREF_RATIO);
//Select DCO as SMCLK source
UCS_initClockSignal(UCS_SMCLK,UCS_DCOCLK_SELECT,UCS_CLOCK_DIVIDER_1);
// Enable global oscillator fault flag
SFR_clearInterrupt(SFR_OSCILLATOR_FAULT_INTERRUPT);
SFR_enableInterrupt(SFR_OSCILLATOR_FAULT_INTERRUPT);
// Enable global interrupt
__bis_SR_register(GIE);
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=UNMI_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(UNMI_VECTOR)))
#endif
void NMI_ISR(void)
{
do
{
// If it still can't clear the oscillator fault flags after the timeout,
// trap and wait here.
status = UCS_clearAllOscFlagsWithTimeout(1000);
}
while(status != 0);
}