Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

BELOW IS CCS PROGRAMMING LANGUAGE PLEASE EXPLAIN WHAT THE CODE IS DOING IN DETAIL. #include #include #include //Exact-width integer types #include //Driver library #define DCO_FREQ

BELOW IS CCS PROGRAMMING LANGUAGE PLEASE EXPLAIN WHAT THE CODE IS DOING IN DETAIL.

#include

#include

#include //Exact-width integer types

#include //Driver library

#define DCO_FREQ 48e6 //unit: Hz; DCO nominal frequencies: 1.5, 3, 6, 12, 24,

48 MHz.

#define TIMER0_FREQ 1 //unit: Hz

#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;

const char *terminalDisplayText[NUM_DISP_TEXT_LINE] =

{

" ",

"UART and LED Demo. ",

"Please type to send to LaunchPad. ",

"> "

};

void main(void)

{

uint32_t i;

initDevice();

initGPIO();

initTimer();

initUART();

//Enable interrupts

Interrupt_enableSleepOnIsrExit();

Interrupt_enableMaster();

Timer32_startTimer(TIMER32_0_BASE, false);

//Initial display on terminal

for(i=0; i

{

uart0_transmitStr(terminalDisplayText[i]);

}

while(1)

{

PCM_gotoLPM0();

}

}

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 P1.0 as output.

//P1.0 is connected to a red LED on LaunchPad.

GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);

}

void initTimer(void)

{

Timer32_initModule(TIMER32_0_BASE, TIMER32_PRESCALER_1, TIMER32_32BIT,

TIMER32_PERIODIC_MODE);

Timer32_setCount(TIMER32_0_BASE, clockMCLK/TIMER0_FREQ);

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/MSP430BaudRateConver

ter/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);

UART_enableInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT);

Interrupt_enableInterrupt(INT_EUSCIA0);

}

// 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);

GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);

}

// Backchannel Application/User UART ISR

void EUSCIA0_IRQHandler(void)

{

uint8_t data;

uint32_t status;

status = UART_getEnabledInterruptStatus(EUSCI_A0_BASE);

UART_clearInterruptFlag(EUSCI_A0_BASE, status);

if(status & EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG)

{

data = UART_receiveData(EUSCI_A0_BASE);

//Directly print the received char to CCS Console Window.

printf("Received: %c ", data);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is Larmors formula? Explain with a suitable example.

Answered: 1 week ago