Question: Below is a code created on CCS for a ti MSP-432 lauchpad. I am trying to Configure DCO frequency to be 12MHz and Configure UART0
Below is a code created on CCS for a ti MSP-432 lauchpad. I am trying to Configure DCO frequency to be 12MHz and Configure UART0 baud-rate to be 115200. (You will also have to change the baud-rate in PuTTY in order to communicate with LaunchPad.) Please explain each new code.
#include
#define DCO_FREQ 48e6 //unit: Hz; DCO nominal frequencies: 1.5, 3, 6, 12, 24, 48 MHz. #define TIMER0_FREQ 1 //unit: Hz
#define RED_LED GPIO_PIN0 #define GREEN_LED GPIO_PIN1 #define BLUE_LED GPIO_PIN2
#define NUM_DISP_TEXT_LINE 4
//function prototypes void initDevice(void); void initGPIO(void); void initTimer(void); void initUART(void);
void uart0_transmitStr(const char *str);
// global variables uint32_t clockMCLK; uint8_t currentLED = RED_LED;
const char *terminalDisplayText[NUM_DISP_TEXT_LINE] = { " ", "UART Demo ", "R: red, G: green, B:blue, H: Help ", "> " };
void main(void) { uint32_t i; uint8_t data;
initDevice(); initGPIO(); initTimer(); initUART();
// Enable interrupts Interrupt_enableMaster();
Timer32_startTimer(TIMER32_0_BASE, false);
//Initial display on terminal. for(i=0; i while(1) { if(UART_getInterruptStatus(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG)) { data = UART_receiveData(EUSCI_A0_BASE); UART_clearInterruptFlag(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG); switch(data) { case 'R': case 'r': currentLED = RED_LED; uart0_transmitStr("Blink red LED. > "); break; case 'G': case 'g': currentLED = GREEN_LED; uart0_transmitStr("Blink green LED. > "); break; case 'B': case 'b': currentLED = BLUE_LED; uart0_transmitStr("Blink blue LED. > "); break; case 'H': case 'h': for(i=0; i void initDevice(void) { WDT_A_holdTimer(); //stop Watchdog timer //Change VCORE to 1 to support a frequency higher than 24MHz. //See data sheet for Flash wait-state requirement for a given frequency. PCM_setPowerState(PCM_AM_LDO_VCORE1); FlashCtl_setWaitState(FLASH_BANK0, 1); FlashCtl_setWaitState(FLASH_BANK1, 1); //Enable FPU for DCO Frequency calculation. FPU_enableModule(); FPU_enableLazyStacking(); // Required to use FPU within ISR. //Only use DCO nominal frequencies: 1.5, 3, 6, 12, 24, 48MHz. CS_setDCOFrequency(DCO_FREQ); //Divider: 1, 2, 4, 8, 16, 32, 64, or 128. //SMCLK used by UART and ADC14. CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); CS_initClockSignal(CS_HSMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_8); CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_16); clockMCLK = CS_getMCLK(); } void initGPIO(void) { //Configure P2.0, P2.1, P2.2 as output. //P2.0, P2.1, P2.2 are connected to a RGB tri-color LED on LaunchPad. GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0|GPIO_PIN1|GPIO_PIN2); } void initTimer(void) { Timer32_initModule(TIMER32_0_BASE, TIMER32_PRESCALER_1, TIMER32_32BIT, TIMER32_PERIODIC_MODE); Timer32_setCount(TIMER32_0_BASE, clockMCLK/TIMER0_FREQ - 1); Timer32_enableInterrupt(TIMER32_0_BASE); Interrupt_enableInterrupt(INT_T32_INT1); //Enable Timer32_0 interrupt in the interrupt controller. } void initUART(void) { //Configuration for 3MHz SMCLK, 9600 baud rate. //Calculated using the online calculator that TI provides at: //http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430BaudRateConverter/index.html const eUSCI_UART_Config config = { EUSCI_A_UART_CLOCKSOURCE_SMCLK, //SMCLK Clock Source 19, //BRDIV = 19 8, //UCxBRF = 8 0, //UCxBRS = 0 EUSCI_A_UART_NO_PARITY, //No Parity EUSCI_A_UART_LSB_FIRST, //MSB First EUSCI_A_UART_ONE_STOP_BIT, //One stop bit EUSCI_A_UART_MODE, //UART mode EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION //Oversampling }; // Configure GPIO pins for UART. RX: P1.2, TX:P1.3. GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN2|GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION); UART_initModule(EUSCI_A0_BASE, &config); UART_enableModule(EUSCI_A0_BASE); } // Transmit a string through UART0. void uart0_transmitStr(const char *str) { uint32_t len, i=0; len = strlen(str); while(i < len) { UART_transmitData(EUSCI_A0_BASE, str[i++]); while(!UART_getInterruptStatus(EUSCI_A0_BASE, EUSCI_A_UART_TRANSMIT_COMPLETE_INTERRUPT_FLAG)); UART_clearInterruptFlag(EUSCI_A0_BASE, EUSCI_A_UART_TRANSMIT_COMPLETE_INTERRUPT_FLAG); } } //Timer32_0 ISR void T32_INT1_IRQHandler(void) { Timer32_clearInterruptFlag(TIMER32_0_BASE); if(GPIO_getInputPinValue(GPIO_PORT_P2, GPIO_PIN0|GPIO_PIN1|GPIO_PIN2)) { GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0|GPIO_PIN1|GPIO_PIN2); } else { GPIO_setOutputHighOnPin(GPIO_PORT_P2, currentLED); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
