/* --COPYRIGHT--,BSD_EX * Copyright (c) 2016, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ******************************************************************************* * * MSP430 CODE EXAMPLE DISCLAIMER * * MSP430 code examples are self-contained low-level programs that typically * demonstrate a single peripheral function or device feature in a highly * concise manner. For this the code may rely on the device's power-on default * register values and settings such as the clock configuration and care must * be taken when combining code from several examples to avoid potential side * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware * for an API functional library-approach to peripheral configuration. * * --/COPYRIGHT-- //****************************************************************************** // MSP430FR235x Demo - eUSCI_A0 UART echo at 4800 baud using BRCLK = 32768Hz. // // Description: This demo echoes back characters received via a PC serial port. // ACLK is used as UART clock source and the device is put in LPM3. // Note that level shifter hardware is needed to shift between RS232 and MSP // voltage levels. // // The example code shows proper initialization of registers // and interrupts to receive and transmit data. // To test code in LPM3, disconnect the debugger. // // ACLK = REFO = 32768Hz, MCLK = SMCLK = DCODIV ~1MHz. // // MSP430FR2355 // ----------------- // /|\| | // | | | // --|RST | // | | // | | // | P4.3/UCA1TXD|----> PC (echo) // | P4.2/UCA1RXD|<---- PC // | | // // Darren Lu // Texas Instruments Inc. // Oct. 2016 // Built with IAR Embedded Workbench v6.50 & Code Composer Studio v6.2 //****************************************************************************** #include void Init_GPIO(); int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer // Configure GPIO Init_GPIO(); PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode // to activate 1previously configured port settings // Configure UART pins P4SEL0 |= BIT2 | BIT3; // set 2-UART pin as second function // Configure UART UCA1CTLW0 |= UCSWRST; UCA1CTLW0 |= UCSSEL_1; // set ACLK as BRCLK // Baud Rate calculation. Referred to UG 17.3.10 // (1) N=32768/4800=6.827 // (2) OS16=0, UCBRx=INT(N)=6 // (4) Fractional portion = 0.827. Refered to UG Table 17-4, UCBRSx=0xEE. UCA1BR0 = 6; // INT(32768/4800) UCA1BR1 = 0x00; UCA1MCTLW = 0xEE00; UCA1CTLW0 &= ~UCSWRST; // Initialize eUSCI UCA1IE |= UCRXIE; // Enable USCI_A0 RX interrupt __bis_SR_register(LPM3_bits|GIE); // Enter LPM3, interrupts enabled __no_operation(); // For debugger } #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=USCI_A1_VECTOR __interrupt void USCI_A1_ISR(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(USCI_A1_VECTOR))) USCI_A1_ISR (void) #else #error Compiler not supported! #endif { switch(__even_in_range(UCA1IV,USCI_UART_UCTXCPTIFG)) { case USCI_NONE: break; case USCI_UART_UCRXIFG: while(!(UCA1IFG&UCTXIFG)); UCA1TXBUF = UCA1RXBUF; __no_operation(); break; case USCI_UART_UCTXIFG: break; case USCI_UART_UCSTTIFG: break; case USCI_UART_UCTXCPTIFG: break; default: break; } } void Init_GPIO() { P1DIR = 0xFF; P2DIR = 0xFF; P1REN = 0xFF; P2REN = 0xFF; P1OUT = 0x00; P2OUT = 0x00; }*/ /* --COPYRIGHT--,BSD_EX * Copyright (c) 2016, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ******************************************************************************* * * MSP430 CODE EXAMPLE DISCLAIMER * * MSP430 code examples are self-contained low-level programs that typically * demonstrate a single peripheral function or device feature in a highly * concise manner. For this the code may rely on the device's power-on default * register values and settings such as the clock configuration and care must * be taken when combining code from several examples to avoid potential side * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware * for an API functional library-approach to peripheral configuration. * * --/COPYRIGHT--*/ //****************************************************************************** // MSP430FR235x Demo - eUSCI_A0 UART echo at 4800 baud using BRCLK = 32768Hz. // // Description: This demo echoes back characters received via a PC serial port. // ACLK is used as UART clock source and the device is put in LPM3. // Note that level shifter hardware is needed to shift between RS232 and MSP // voltage levels. // // The example code shows proper initialization of registers // and interrupts to receive and transmit data. // To test code in LPM3, disconnect the debugger. // // ACLK = REFO = 32768Hz, MCLK = SMCLK = DCODIV ~1MHz. // // MSP430FR2355 // ----------------- // /|\| | // | | | // --|RST | // | | // | | // | P4.3/UCA1TXD|----> PC (echo) // | P4.2/UCA1RXD|<---- PC // | | // Rata de transfer: 4800 bps //****************************************************************************** #include void Init_GPIO(); unsigned char data=120; //'x' x mic unsigned char sir[5]={'T','e','m','p',':',10}; unsigned int i=0; int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer // Configure GPIO Init_GPIO(); // config P4.1 P4OUT |= BIT1; // Configure P1.3 as pulled-up P4REN |= BIT1; // P1.3 pull-up register enable P4IES |= BIT1; // P1.3 Hi/Low edge P4IE |= BIT1; // P1.3 interrupt enabled // operation at 24MHz(beyond 8MHz) _before_ configuring the clock system. FRCTL0 = FRCTLPW | NWAITS_2; __bis_SR_register(SCG0); // disable FLL CSCTL3 |= SELREF__REFOCLK; // Set REFO as FLL reference source CSCTL0 = 0; // clear DCO and MOD registers CSCTL1 |= DCORSEL_7; // Set DCO = 24MHz CSCTL2 = FLLD_0 + 731; // DCOCLKDIV = 24MHz __delay_cycles(3); __bic_SR_register(SCG0); // enable FLL while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1)); // FLL locked CSCTL4 = SELMS__DCOCLKDIV | SELA__REFOCLK; // set default REFO(~32768Hz) as ACLK source, ACLK = 32768Hz // default DCOCLKDIV as MCLK and SMCLK source P1DIR |= BIT0 | BIT1 | BIT2; // set ACLK SMCLK and LED pin as output P1SEL1 |= BIT0 | BIT1; // set ACLK and SMCLK pin as second function PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode // clear P4.1 // to activate 1previously configured port settings P4IFG &= ~BIT1; // Configure UART pins P4SEL0 |= BIT2 | BIT3; // set 2-UART pin as second function // Configure UART UCA1CTLW0 |= UCSWRST; UCA1CTLW0 |= UCSSEL_2; // set SMCLK // Baud Rate calculation. Referred to UG 17.3.10 // (1) N=24000000/115200=208.33 // (3) OS16=1, UCBRx = 13; //(4)UCBRFx=0 //UCBRSx=0x49 //Registri UCA1BR0 = 13; // INT(32768/4800) UCA1BR1 = 0x00; // UCA1BRW = 13 = 0x000D; UCA1MCTLW = 0x4901; UCA1CTLW0 &= ~UCSWRST; // Initialize eUSCI UCA1IE |= UCRXIE; // Enable USCI_A0 RX interrupt __bis_SR_register(LPM3_bits|GIE); // Enter LPM3, interrupts enabled __no_operation(); // For debugger } #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=USCI_A1_VECTOR __interrupt void USCI_A1_ISR(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(USCI_A1_VECTOR))) USCI_A1_ISR (void) #else #error Compiler not supported! #endif { switch(__even_in_range(UCA1IV,USCI_UART_UCTXCPTIFG)) { case USCI_NONE: break; case USCI_UART_UCRXIFG: while(!(UCA1IFG&UCTXIFG)); data=UCA1RXBUF; UCA1TXBUF = UCA1RXBUF; __no_operation(); break; case USCI_UART_UCTXIFG: break; case USCI_UART_UCSTTIFG: break; case USCI_UART_UCTXCPTIFG: break; default: break; } } // Port 4 interrupt service routine #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=PORT4_VECTOR __interrupt void Port_4(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(PORT4_VECTOR))) Port_4 (void) #else #error Compiler not supported! #endif { P4IFG &= ~BIT1; // Clear P1.3 IFG /* while(!(UCA1IFG&UCTXIFG));// este o transmisie activa? UCA1TXBUF = data;// incarca 'x' in registrul de transmisie */ //for(i=0;i<7;i++) // { while(!(UCA1IFG&UCTXIFG));// este o transmisie activa? UCA1TXBUF = sir[i];// data; incarca 'x' in registrul de transmisie // } // i=0; __bic_SR_register_on_exit(LPM3_bits); // Exit LPM3 } void Init_GPIO() { P1DIR = 0xFF; P2DIR = 0xFF; P1REN = 0xFF; P2REN = 0xFF; P1OUT = 0x00; P2OUT = 0x00; }