Serial communication between MSP4. Launchpad and PCIn MSP4. USCI (Universal Serial Communications Interface). The peripheral is designed in such a way that it can handle multiple serial communication formats ,synchronous as well as asynchronous like SPI,I2. C,Ir. DA,UART etc. MSP4. 30. G2. 55. USCI modules names as USCI_A0 and USCI_B0 for handling multiple communication formats. USCI_A0 can be configured to handle LIN,Ir. ![]() This article shows how to communicated with Serial Port using C#.DA,SPI and asynchronous serial communication (UART) while USCI_B0 can handle SPI and I2. C. In this article we we will configure USCI_A0 in MSP4. G2. 55. 3 to handle asynchronous serial communication or commonly known as UART mode. The UART mode uses two pins to transmit(UCA0. TXD) and receive data(UCA0. RXD) . Asynchronous serial communication is widely used for communicating with external devices like PC/Laptops,GSM modems,GPS modules etc. It also forms the basis for many standard protocols like RS2. RS4. 22,RS4. 85 etc. You can see the (very) simplified block diagram of USCI_A0 in UART mode below. In this example we are going to configure the MSP4. UART to transmit and receive at 9. Parity and 1 Stop bit . In the above figure you can see that the USCI can source clock from either SMCLK or ACLK to generate BRCLK which is then used to generate the required timings. UC0. CLK is external clock sourced from outside through MSP4. Here I am going to configure the DCO to generate 1. MHz and use SMCLK as UART clock. In computing, a serial port is a serial communication interface through which information transfers in or out one bit at a time (in contrast to a parallel port. Connecting external electonics using the serial port. For hobbyists and educators. To generate accurate 1. MHz clock I am going to load the caliberation constants into the Basic clock system register and DCO control registers like thisif (CALBC1_1. Speed Hardware implementation difficulty Serial Port Very slow (< E5 bit/s) Medium Parallel Port Slow (~ E6 bit/s) Easy ISA Card Medium (~ E7 bit/s). MHZ == 0x. FF) // If calibration constant erased{ while(1); // do not load, trap CPU!!} DCOCTL = 0; // Select lowest DCOx and MODx settings. BCSCTL1 = CALBC1_1. MHZ; // Set range. DCOCTL = CALDCO_1. MHZ; // Set DCO step + modulation CALBC1_1. MHZ is a constant defined in the header file msp. DCO to operate at 1,8,1.MHz (CALBC1_1. MHZ,CALBC1_8.MHZ,CALBC1_1. 2MHZ,CALBC1_1. Address Book On Microsoft Outlook . MHZ). Registers Required for UART After configuring the system clock to 1.MHz, we are going to look into the registers and bits that are important for configuring the UART. Please note that only relevant registers and bits will be explained . UCAx. CTL0 (USCI_Ax Control register. USC1_A0 so UCA0. CTL0 - This register controls the settings for Parity selection,direction of data transmission(LSB or MSB first),character length,no of stop bits,modes of serial transmission. The important bits are. UCPENUsed for enabling or disabling parity (In our case no parity so UCPEN = 0)UCPARUsed for selecting between EVEN or ODD parity (not used since we are disabling parity)UCMSBControls the direction of receive and transmit shift register(here LSB first)UC7. BITSelects the character length 7/8 bit(we are using 8 bit so 0)UCSPBNumber of stopbits (here 1 so UCSPB = 0)UCMODEx. UCSYNC = 0. Here we are using the default UART mode. Other modes are used with multiprocessor serial communication and for automatic baudrate detection UCSYNCSelecting between asynchronous(UART) and synchronous modes(SPI)In our case ,all the bits in UCA0. CTL0 are zero so we won't be configuring that register in our program. UCAx. CTL1 here UCA0. CTL1- The two important bits contained in this register are UCSSELx. These bits are used to select the clock source to the USCI module. In our case we are going to select SMCLK @1. MHz. UCSWRSTThis bit is used to put the USCI module in reset state . It is recommended to put the USCI module in reset state before making any changes to the registers. UCAx. STAT here UCA0. STAT- The two important bits contained in this register are. UCLISTENThis bit is used to select the internal loop back mode. In loop back mode UCAx. TXD is internally fed back to the receiver. UCBUSY Indicates if a transmit or receive operation is in progress. UCAx. BR0 (UCA0. BR0) and UCAx. BR1 (UCA0. BR1) are two 8 bit registers which are used to set the clock prescalar value for the Baud rate generator. UCAx. TXBUF (UCA0. TXBUF) 8 bit data register for holding the byte to be transmitted by the MSP4. UART. 6) UCAx. RXBUF (UCA0. RXBUF) 8 bit data register that stores the received byte. Configuring the Baud rate MSP4. Easiest way to configure the baud rate of a MSP4. Baud rate selection table listed in the usermanual. Just find out the UCBRx values corrosponding to your BRCLK frequency and the baud rate you wish to use . After finding out values just put them in the UCA0. BR0 and UCA0. BR1 register to configure the baud rate. In our case we are using SMCLK @ 1. MHz as BRCLK and 9. Now check the table for the corresponding UCBRx value (here 1. UCA0. BR0 and UCA0. BR1 registers to configure the baud rate. You can find the below table in the MSP4. Another register you should consider while configuring the baud rate is the UCAx. MCTL (UCA0. MCTL) which is used to select the modulation stage. Put the UCBRSx value (here 1) corresponding to the selected baud rate in the UCA0. MCTL register to configure the modulation stage Interrupts of MSP4. UARTMSP4. 30. G2. The transmit and reception intterrupts have to be enabled in the IE2 register before they can be used. Two flags in the IFG2 register are used to indicate whether data is transmitted or received. IE2. UCA0. TXIEUsed to enable/disable the transmit interrupt. UCA0. RXIEUsed to enable/disable the receive interrupt. IFG2. UCA0. TXIFGUSCI_A0 transmit interrupt flag is set when UCA0. TXBUF is empty. UCA0. RXIFGUSCI_A0 receive interrupt flag is set when UCA0. RXBUF have received a complete character. Writing the Code One problem with writing code for communicating with two devices is that ,it is quite difficult to pin point the problem when something goes wrong . The problem could be with your code ,or the communication cable or the code running on the other device etc. In order to make it easy for developing UART code,MSP4. Loop Back mode. In Loop back mode the output of the transmitter is internally connected to the input of the receiver,so what ever the MSP4. In this example we are going to write simple communication program which uses the loop back mode and communicates at 9. N1). Here I am using IAR embedded workbench for MSP4. IAR. If you are not familiar with IAR EW you can check out a short tutorial here . The code given below will configure the UART and transmit an ascii character 'A' . The UART is configured in loop back mode so 'A' is received back and is stored in UCA0. RXBUF. LED connected to P1. A' is transmitted and LED connected to P1. A' is received back. #include "msp. WDTCTL = WDTPW + WDTHOLD; // Stop the Watch dog//- -- -- -- -- -- -- -- -- -- Configure the Clocks - -- -- -- -- -- -- -- -- -- //if (CALBC1_1. MHZ==0x. FF) // If calibration constant erased{ while(1); // do not load, trap CPU!!} DCOCTL = 0; // Select lowest DCOx and MODx settings. BCSCTL1 = CALBC1_1. MHZ; // Set range. DCOCTL = CALDCO_1. MHZ; // Set DCO step + modulation //- -- -- -- -- -- -- -- - Configuring the LED's - -- -- -- -- -- -- -- -- -- -- -//P1. DIR |= BIT0 + BIT6; // P1. P1. 6 output. P1. OUT & = ~BIT0 + BIT6; // P1. P1. 6 = 0//- -- -- -- -- Setting the UART function for P1. P1. 2 - -- -- -- -//P1. SEL |= BIT1 + BIT2; // P1. UCA0. RXD input P1. SEL2 |= BIT1 + BIT2; // P1. UCA0. TXD output //- -- -- -- -- -- - Configuring the UART(USCI_A0) - -- -- -- -- -- -- -- -//UCA0. CTL1 |= UCSSEL_2 + UCSWRST; // USCI Clock = SMCLK,USCI_A0 disabled. UCA0. BR0 = 1. From datasheet table- UCA0. BR1 = 0; // - selects baudrate =9. SMCLKUCA0. MCTL = UCBRS_1; // Modulation value = 1 from datasheet UCA0. STAT |= UCLISTEN; // loop back mode enabled UCA0. CTL1 & = ~UCSWRST; // Clear UCSWRST to enable USCI_A0 //- -- -- -- -- -- -- -- - Enabling the interrupts - -- -- -- -- -- -- -- -- -//IE2 |= UCA0.TXIE; // Enable the Transmit interrupt.IE2 |= UCA0. RXIE; // Enable the Receive interrupt_BIS_SR(GIE); // Enable the global interrupt. . UCA0. TXBUF = 'A'; // Transmit a byte _BIS_SR(LPM0_bits + GIE); // Going to LPM0} //- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- //// Transmit and Receive interrupts ////- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- // #pragma vector = USCIAB0.TX_VECTOR__interrupt void Transmit. Interrupt(void){P1. Adobe Fireworks Free Download Crack Idm .
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
August 2018
Categories |