// // BlimpBot // CSE 466 final project // Josh Green, Baron Oldenburg, Henry Baba-Weiss // #include #include "bsp.h" #include "virtual_com_cmds.h" // Specialized version of the normal COM_Init function that is tweaked to work // with the MSP430f5510 on the blimps. void COM_Init() { //................ UCSCTL3 = SELREF_2; // Set DCO FLL reference = REFO UCSCTL4 |= SELA_2; // Set ACLK = REFO UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx // Loop until XT1,XT2 & DCO stabilizes - In this case only DCO has to stabilize do { UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG); // Clear XT2,XT1,DCO fault flags SFRIFG1 &= ~OFIFG; // Clear fault flags } while (SFRIFG1&OFIFG); // Test oscillator fault flag __bis_SR_register(SCG0); // Disable the FLL control loop UCSCTL1 = DCORSEL_5; // Select DCO range 16MHz operation UCSCTL2 |= 255; // Set DCO Multiplier for 8MHz // (N + 1) * FLLRef = Fdco // (249 + 1) * 32768 = 8MHz __bic_SR_register(SCG0); // Enable the FLL control loop // Worst-case settling time for the DCO when the DCO range bits have been // changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx // UG for optimization. // 32 x 32 x 8 MHz / 32,768 Hz = 250000 = MCLK cycles for DCO to settle __delay_cycles(250000); P4SEL = BIT4+BIT5; // P3.4,5 = USCI_A0 TXD/RXD UCA1CTL1 |= UCSWRST; // **Put state machine in reset** UCA1CTL1 |= UCSSEL__SMCLK; // CLK = SMCLK UCA1BR0 = 54; // UCA1BR1 = 0; // UCA1MCTL = UCBRS_0 + UCBRF_10 + UCOS16; // Modulation UCBRSx=0, UCBRFx=10 UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine** UCA1IE |= UCRXIE; // Enable USCI_A0 RX interrupt } // Transfers the given string over the UCSI UART port. Uses explicit length, instead // of looking for a null byte to terminate the string. void TXString(char* string, int length) { int pointer; for( pointer = 0; pointer < length; pointer++) { UCA1TXBUF = string[pointer]; while (!(UCA1IFG & UCTXIFG)); // USCI_A0 TX buffer ready? } }