Question
HELP WITH THE TODOs' #include typedef enum {baud9600, baud19200, baud38400, baud57600} UARTBaudRate_t; #define no_API 1 #if no_API int main(void) { WDT_A_hold(WDT_A_BASE); eUSCI_UART_Config uartConfig = {
HELP WITH THE TODOs'
#include
typedef enum {baud9600, baud19200, baud38400, baud57600} UARTBaudRate_t;
#define no_API 1
#if no_API
int main(void) {
WDT_A_hold(WDT_A_BASE);
eUSCI_UART_Config uartConfig = { EUSCI_A_UART_CLOCKSOURCE_SMCLK, // SMCLK Clock Source = 3MHz 19, // UCBR = 19 8, // UCBRF = 8 0x55, // UCBRS = 0x55 (table lookup for 0.5) EUSCI_A_UART_NO_PARITY, // No Parity EUSCI_A_UART_LSB_FIRST, // LSB First EUSCI_A_UART_ONE_STOP_BIT, // One stop bit EUSCI_A_UART_MODE, // UART mode EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION // Oversampling };
UART_initModule(EUSCI_A0_BASE, &uartConfig); UART_enableModule(EUSCI_A0_BASE); GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
char rChar, tChar; int i=0; while (1) { if (UART_getInterruptStatus (EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG) == EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG) { rChar = UART_receiveData(EUSCI_A0_BASE); i++;
// Depending on if the received char is a Number, a Letter, or Otherwise, the transmit char is N, L or O if (('0'<=rChar) && (rChar <= '9')) tChar = 'N'; else if ((('a'<=rChar) && (rChar <= 'z')) || (('A'<=rChar) && (rChar <= 'Z'))) tChar = 'L'; else tChar = 'O';
if (UART_getInterruptStatus (EUSCI_A0_BASE, EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG) == EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG) UART_transmitData(EUSCI_A0_BASE, tChar); }
switch (i) { // After analyzing 5 characters, it switches the speed to 19600 case 5: uartConfig.clockPrescalar = 9; uartConfig.firstModReg = 12; uartConfig.secondModReg = 0x22; // table lookup for 0.25 UART_initModule(EUSCI_A0_BASE, &uartConfig); UART_enableModule(EUSCI_A0_BASE); i++; break;
// TODO #1: (10 points) // add code here to support the other two baudrates enumarted in this program (at the top) case 10:
i++; break;
case 15: break; } }
}
#else
// TODO #2: (10 points) write a comment above each function briefly describing what it does. // TODO #3: (30 points) write the body of all the functions
void InitUART(uint32_t moduleInstance, const eUSCI_UART_Config *uartConfig_p, uint_fast8_t selectedPort, uint_fast16_t selectedPins) { }
void UpdateUART(uint32_t moduleInstance, const eUSCI_UART_Config *uartConfig_p) { }
bool UARTHasChar(uint32_t moduleInstance) { }
uint8_t UARTGetChar(uint32_t moduleInstance) { }
bool UARTCanSend(uint32_t moduleInstance) { }
void UARTPutChar(uint32_t moduleInstance, uint8_t tChar) { }
void UARTSetBaud(uint32_t moduleInstance, eUSCI_UART_Config *uartConfig_p, UARTBaudRate_t newBaud) { }
int main(void) { WDT_A_hold(WDT_A_BASE);
eUSCI_UART_Config uartConfig = { EUSCI_A_UART_CLOCKSOURCE_SMCLK, // SMCLK Clock Source = 3MHz 19, // UCBR = 19 8, // UCBRF = 8 0xAA, // UCBRS = 0xAA EUSCI_A_UART_NO_PARITY, // No Parity EUSCI_A_UART_LSB_FIRST, // LSB First EUSCI_A_UART_ONE_STOP_BIT, // One stop bit EUSCI_A_UART_MODE, // UART mode EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION // Oversampling };
InitUART(EUSCI_A0_BASE, &uartConfig, GPIO_PORT_P1, GPIO_PIN2 | GPIO_PIN3);
uint8_t rChar, tChar; int i = 0; while (1) { if (UARTHasChar(EUSCI_A0_BASE)) { rChar = UARTGetChar(EUSCI_A0_BASE); i++;
// Depending on if the received char is a Number, a Letter, or Otherwise, // the transmit char is N, L or O if (('0'<=rChar) && (rChar <= '9')) tChar = 'N'; else if ((('a'<=rChar) && (rChar <= 'z')) || (('A'<=rChar) && (rChar <= 'Z'))) tChar = 'L'; else tChar = 'O';
if (UARTCanSend(EUSCI_A0_BASE)) UARTPutChar(EUSCI_A0_BASE, tChar); }
switch (i) { // After analyzing 5 characters, it switches the speed to 19600 case 5: UARTSetBaud(EUSCI_A0_BASE, &uartConfig, baud19200); i++; break;
case 10: UARTSetBaud(EUSCI_A0_BASE, &uartConfig, baud38400); i++; break; case 15: UARTSetBaud(EUSCI_A0_BASE, &uartConfig, baud57600); } } } #endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started