Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "main.h"
- #include <stdio.h>
- #include <string.h>
- #include "driverlib.h"
- extern int mode;
- extern int pingHost;
- uint8_t RXData = 0; // UART Receive byte
- bool status = 1;
- bool sleep = 0;
- bool wakeup = 0;
- bool status2 = 0;
- uint16_t SWPressed = 0;
- void Init_GPIO(void);
- void Init_Clock(void);
- void Init_UART(void);
- //-----------------------------------------------------------------------------
- int _system_pre_init(void)
- {
- // Stop Watchdog timer
- WDT_A_hold(__MSP430_BASEADDRESS_WDT_A__); // Stop WDT
- GPIO_setOutputHighOnPin(GPIO_PORT_P4, GPIO_PIN0);
- GPIO_setAsOutputPin(GPIO_PORT_P4, GPIO_PIN0);
- /*==================================*/
- /* Choose if segment initialization */
- /* should be done or not. */
- /* Return: 0 to omit initialization */
- /* 1 to run initialization */
- /*==================================*/
- return 1;
- }
- void reset_gpio()
- {
- P1DIR = 0xFF;
- P2DIR = 0xE7;
- P3DIR = 0xFF;
- P4DIR = 0xFF;
- P2SEL0 &= ~BIT0;
- P2SEL1 &= ~BIT0;
- P2SEL0 &= ~BIT1;
- P2SEL1 &= ~BIT1;
- P2SEL0 &= ~BIT5;
- P2SEL1 &= ~BIT5;
- P2SEL0 &= ~BIT6;
- P2SEL1 &= ~BIT6;
- P4SEL0 &= ~BIT0;
- P4SEL1 &= ~BIT0;
- PJSEL0 = 0;
- PJSEL1 = 0;
- }
- /*
- * main.c
- */
- int main(void) {
- Init_Clock();
- Init_GPIO();
- Init_UART();
- printf("test \n");
- __delay_cycles(1000);
- EUSCI_A_UART_disable(EUSCI_A0_BASE);
- reset_gpio();
- PMMCTL0_H = PMMPW_H; // Open PMM Registers for write
- PMMCTL0_L &= ~(SVSHE); // Disable high-side SVS
- PMMCTL0_L |= PMMREGOFF; // and set PMMREGOFF
- PMMCTL0_H = 0; // Lock PMM Registers
- __bic_SR_register(GIE);
- __bis_SR_register(LPM4_bits);
- __no_operation();
- }
- int fputc(int _c, register FILE *_fp)
- {
- EUSCI_A_UART_transmitData(EUSCI_A0_BASE, _c);
- return((unsigned char)_c);
- }
- int fputs(const char *_ptr, register FILE *_fp)
- {
- unsigned int i, len;
- len = strlen(_ptr);
- for(i=0 ; i<len ; i++)
- {
- fputc(_ptr[i], _fp);
- }
- return len;
- }
- /*
- * GPIO Initialization
- */
- void Init_GPIO()
- {
- // Set all GPIO pins to output low for low power
- GPIO_setAsOutputPin(
- GPIO_PORT_P1,
- GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4
- | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7);
- GPIO_setAsOutputPin(
- GPIO_PORT_P2,
- GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4
- | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7);
- GPIO_setAsOutputPin(
- GPIO_PORT_P3,
- GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4
- | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7);
- GPIO_setAsOutputPin(
- GPIO_PORT_P4,
- GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4
- | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7);
- GPIO_setAsOutputPin(
- GPIO_PORT_PJ,
- GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4
- | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 | GPIO_PIN8 | GPIO_PIN9
- | GPIO_PIN10 | GPIO_PIN11 | GPIO_PIN12 | GPIO_PIN13
- | GPIO_PIN14 | GPIO_PIN15);
- // Set all GPIO pins to output low for low power
- GPIO_setOutputLowOnPin(
- GPIO_PORT_P1,
- GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4
- | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7);
- GPIO_setOutputLowOnPin(
- GPIO_PORT_P2,
- GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4
- | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7);
- GPIO_setOutputLowOnPin(
- GPIO_PORT_P3,
- GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4
- | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7);
- GPIO_setOutputLowOnPin(
- GPIO_PORT_P4,
- GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5
- | GPIO_PIN6 | GPIO_PIN7);
- GPIO_setOutputLowOnPin(
- GPIO_PORT_PJ,
- GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4
- | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 | GPIO_PIN8 | GPIO_PIN9
- | GPIO_PIN10 | GPIO_PIN11 | GPIO_PIN12 | GPIO_PIN13
- | GPIO_PIN14 | GPIO_PIN15);
- // Configure P2.0 - UCA0TXD and P2.1 - UCA0RXD
- // GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0);
- // GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0);
- //
- GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN0, GPIO_SECONDARY_MODULE_FUNCTION);
- GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P2, GPIO_PIN1, GPIO_SECONDARY_MODULE_FUNCTION);
- // Set PJ.4 and PJ.5 as Primary Module Function Input, LFXT.
- GPIO_setAsPeripheralModuleFunctionInputPin(
- GPIO_PORT_PJ,
- GPIO_PIN4 + GPIO_PIN5,
- GPIO_PRIMARY_MODULE_FUNCTION
- );
- // Disable the GPIO power-on default high-impedance mode
- // to activate previously configured port settings
- PMM_unlockLPM5();
- }
- /*
- * Clock System Initialization
- */
- void Init_Clock()
- {
- // Set DCO frequency to 8 MHz
- CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_6);
- //Set external clock frequency to 32.768 KHz
- CS_setExternalClockSource(32768, 0);
- //Set ACLK=LFXT
- CS_initClockSignal(CS_ACLK, CS_LFXTCLK_SELECT, CS_CLOCK_DIVIDER_1);
- // Set SMCLK = DCO with frequency divider of 1
- CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1);
- // Set MCLK = DCO with frequency divider of 1
- CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1);
- //Start XT1 with no time out
- // CS_turnOnLFXT(CS_LFXT_DRIVE_3);
- }
- /*
- * UART Communication Initialization
- */
- void Init_UART()
- {
- // Configure USCI_A0 on 115200
- EUSCI_A_UART_initParam param = {0};
- param.selectClockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK;
- param.clockPrescalar = 4;
- param.firstModReg = 5;
- param.secondModReg = 0x55;
- param.parity = EUSCI_A_UART_NO_PARITY;
- param.msborLsbFirst = EUSCI_A_UART_LSB_FIRST;
- param.numberofStopBits = EUSCI_A_UART_ONE_STOP_BIT;
- param.uartMode = EUSCI_A_UART_MODE;
- param.overSampling = EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION;
- if(STATUS_FAIL == EUSCI_A_UART_init(EUSCI_A0_BASE, ¶m))
- return;
- EUSCI_A_UART_enable(EUSCI_A0_BASE);
- EUSCI_A_UART_clearInterrupt(EUSCI_A0_BASE,
- EUSCI_A_UART_RECEIVE_INTERRUPT);
- // Enable USCI_A0 RX interrupt
- EUSCI_A_UART_enableInterrupt(EUSCI_A0_BASE,
- EUSCI_A_UART_RECEIVE_INTERRUPT); // Enable interrupt
- // Enable globale interrupt
- // __enable_interrupt();
- }
- /*
- * USCI_A0 Interrupt Service Routine that receives PC GUI's commands
- */
- #pragma vector = USCI_A0_VECTOR
- __interrupt void USCI_A0_ISR(void)
- {
- switch (__even_in_range(UCA0IV, USCI_UART_UCTXCPTIFG)) {
- case USCI_NONE:
- break;
- case USCI_UART_UCRXIFG:
- RXData = EUSCI_A_UART_receiveData(EUSCI_A0_BASE);
- printf(RXData);
- break;
- case USCI_UART_UCTXIFG:
- break;
- case USCI_UART_UCSTTIFG:
- break;
- case USCI_UART_UCTXCPTIFG:
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement