Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Explain how dereferencing the TxArray pointer allows testing the value of each character in the array? /* Example code demonstrating the use of the hardware

Explain how dereferencing the TxArray pointer allows testing the value of each character in the array?

/* Example code demonstrating the use of the hardware UART on the MSP430FR2433 to receive * and transmit data back to a host computer over the USB connection on the MSP430 * launchpad. * * This demo will turn on the Red LED if an R is sent and turn it off if a r is sent. * Similarly G and g will turn on and off the green LED * It also transmits the received character back to the terminal. * Sendimg L command will list the string 10 times * originally derived from * https://bennthomsen.wordpress.com/engineering-toolbox/ti-msp430-launchpad/msp430g2553-hardware-uart/ * * Type R turn on red led, r turns off * Type G turn on green led, g turns off * echos with Received command: * Type L list sentence 10 times * or Unknown Command: * */ #include  #include  // use for sprintf(), no putchar() required; void UARTSendArray( char TxArray[]); // our simple printf() unsigned char data; // received char data char MyString [25]; // work buffer for sprintf() int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT // clock system setup __bis_SR_register(SCG0); // disable FLL CSCTL3 |= SELREF__REFOCLK; // Set REFOCLK as FLL reference source CSCTL0 = 0; // clear DCO and MOD registers CSCTL1 &= ~(DCORSEL_7); // Clear DCO frequency select bits first CSCTL1 |= DCORSEL_3; // Set DCOCLK = 8MHz CSCTL2 = FLLD_1 + 121; // FLLD = 1, DCODIV = 4MHz __delay_cycles(3); __bic_SR_register(SCG0); // enable FLL while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1)); // Poll until FLL is locked CSCTL4 = SELMS__DCOCLKDIV | SELA__XT1CLK; // set ACLK = XT1 = 32768Hz, DCOCLK as MCLK and SMCLK source CSCTL5 |= DIVM1; // SMCLK = MCLK = DCODIV/2 = 1MHz, by default PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode // to activate 1previously configured port settings P1DIR |= BIT0 | BIT1 ; // RED = 0, GREEN = 1 P1OUT &= ~(BIT0 | BIT1); // Clear P1.0 /* Configure hardware UART */ // Configure UART pins P1SEL0 |= BIT4 | BIT5; // set 2-UART pin as second function P1.4 - TX P1.5 RX // Configure UART UCA0CTLW0 |= UCSWRST; UCA0CTLW0 |= UCSSEL__SMCLK; UCA0BR0 = 107; // 1MHz SMCLK/9600 BAUD // UCA0BR1 = 0x00; UCA0MCTLW = 0x1100; // | UCOS16 | UCBRF_1; UCA0CTLW0 &= ~UCSWRST; UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt // wait for input UARTSendArray("Waiting on input: "); // Polled ouptut, so can send w/o GIE __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled, wait for command } // RXed character ISR - others unused #pragma vector=USCI_A0_VECTOR __interrupt void USCI_A0_ISR(void) { // decode the UART Interrupt Vector see 21.4.12 UCAxIV Register switch(UCA0IV) { case USCI_NONE: break; case USCI_UART_UCRXIFG: data = UCA0RXBUF; // read the received char - also clears Interrupt // // Echo received char // while(!(UCA0IFG & UCTXIFG)); // Wait for TX buffer to be ready for new data // UCA0TXBUF = data; //Echo Write the character at the location specified py the pointer RxInput(); // process the received char break; case USCI_UART_UCTXIFG: // Tx Interrupt - unused break; case USCI_UART_UCSTTIFG: break; // unused case USCI_UART_UCTXCPTIFG: break; // unused } } void RxInput() { // use sprintf to prepare string for output sprintf(MyString, "Received command: %c ", data); UARTSendArray(MyString); switch(data) { case 'R': { P1OUT |= BIT0; } break; case 'r': { P1OUT &= ~BIT0; } break; case 'G': { P1OUT |= BIT1; } break; case 'g': { P1OUT &= ~BIT1; } break; case 'L': { int i; for (i=0; i<10; i++) { sprintf(MyString, "MyString Value: %d ",i); UARTSendArray(MyString); } break; } default: { UARTSendArray("Unknown Command: "); } break; } } void UARTSendArray(char *TxArray) { // send a 'C' language string to the transmit port // string has to be terminated with a binary '0' (according to C conventions) // blocking is implicit in this function (will wait to finish string before returning) // Impossible to run Tx Interrupt without circular queue while(*TxArray) // loop until binary zero (EOS) { while(!(UCA0IFG & UCTXIFG)); // Wait for TX buffer to be ready for new data UCA0TXBUF = *TxArray++; //Write the character at the location specified py the pointer } } 

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

Recommended Textbook for

What Is A Database And How Do I Use It

Authors: Matt Anniss

1st Edition

1622750799, 978-1622750795

More Books

Students also viewed these Databases questions

Question

How is the Internet changing the field of marketing research?

Answered: 1 week ago

Question

8. Managers are not trained to be innovation leaders.

Answered: 1 week ago

Question

b. Where did they come from?

Answered: 1 week ago

Question

c. What were the reasons for their move? Did they come voluntarily?

Answered: 1 week ago

Question

5. How do economic situations affect intergroup relations?

Answered: 1 week ago