Question: HELP WITH THE TODOs' ( Install MobaXterm on your PC and create a 9600 baudrate connection with your board using the instructions provided here. 2)
HELP WITH THE TODOs'
(
Install MobaXterm on your PC and create a 9600 baudrate connection with your board using the instructions provided here.
2) Compile and debug HW5_uart_starter project from CCS. Make sure to press the green play button.
3) Go back to the MobaXterm window on your PC and type a few characters. Type at least one letter, one number, and one of some other character. You should see the letter L (for Letter) to appear whenever you type a letter, the letter N (for Number) appear whenever you type a number, and the letter O (for Other) to appear when you type some other non - letter, and non - number character. After about five characters, you will see a nonsensical character to appear and perhaps continue like that.
4) Close the 9600 baudrate connection on MobaXterm and open a new one at 19600 speed, repeat step 3. You will see the program starts to work correctly again. This is because, inside our CCS project, we change the speed of the UART connection after 5 characters and the PC is first unaware of this and misinterprets the characters. Once you open a 19600 channel again, things go back to normal as the sender and receiver are communicating at the same speed.
5) Go to the HW5_uart_starter_main.c and carefully study the code. You might realize the code is not commented well. This is done on purpose. We encourage you to click on the driverlib function names while holding down the Ctrl key on your keyboard. This will take you to the function declarations where you can learn about these functions. Comment the code to the point that helps you navigate the program.
6) Implement TODO #1 by copying the code from case 5 and replacing numbers such that the new baudrate speeds are achieved. (These speeds are mentioned in the enum at the top of the program.)
7) Check your code, by compiling and debugging again. This time you need to change the speed of t he connection from the MobaXterm two more times on top of the first time to see if your code works correctly.
8) On th e line #5 of the code, change 1 to 0. This will disable the part of the code you have been working on, and compile the section below it, which has be)
#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
Get step-by-step solutions from verified subject matter experts
