Firmware > UART communications
Contents
Initialization: Frequency Calibration | Baud Rate Setting | Device Pin Selection | USCI Initialization | Interrupt Enabling
Transmission of Data | Reception of Data
Basic Overview:
Basic communication between the transmission hardware and wireless components was established through a data relay using universal serial communication interface (USCI) modules. All micro-controller devices used included at least one USCI module that also provided extended support for multiple serial communication modes with one hardware module. However, for the purpose of this lab, only the universal asynchronous receiver/transmitter (UART) mode was used in order to achieve both bi-directionality and data asynchony. The UART on each device was set to read/transfer data at a baud rate of 9600 and communicate asynchronously. | Back to contents |
Initialization:
Initialization of the built-in USCI module on each microcontroller varied depending on its model but mainly consisted of five basic steps.
Frequency Calibration
The first step consisted of initializing and calibrating the frequency of each microprocessor. Because the UART sends and receives data using clock signals, accurate timing is required in order to ensure quality data transmission. However, by default, the basic clock and digitally controlled oscillator (DCO) always operates within a certain frequency range that widely fluctuates depending on its current operating conditions. Through the use of calibration (either through control register settings or through a frequency-locked loop), the basic clock and DCO frequency is stabilized almost exactly around one particular chosen frequency rate. | Back to contents |
Baud Rate Setting
The second step included establishing a consistent baud rate across all the UART modules and setting the control registers accordingly in order to establish proper operation of UART communication. Regardless of the frequency set in the earlier stage, the baud rate used for this lab was capped at 9600 due to the baud rate limitations of the MSP-eZ430U debugging interface connected to the computer (see referenced debugger datasheet). | Back to contents |
Device Pin Selection
The third was the activation and selection of device pins on the microcontroller for UART output and input. Because each microcontroller already had support for a UART mode, each microcontroller already had certain pins within its layout that could be used for UART transmission and reception. As a result of selecting these two specific pins, the USCI module is initialized to operate in the UART mode. | Back to contents |
USCI Initialization
Fourth, the USCI reset bit was cleared, initializing the state machine and activating UART functionality on the microprocessors. By default, the USCI module was disabled on all the mircroprocessors and was configured to run in a different mode. By doing the pin initialization (described in the above section) and disabling the UCSI reset pin, the USCI module was activated and set to operate in the desired UART mode. | Back to contents |
Interrupt Enabling
Finally, interrupts for the UART were enabled by setting the appropriate bits in the interrupt control register. For this lab, our group did not utilize the transmit interrupt routine; thus, no interrupts were called upon completion of data sending. On the other hand, the receive interrupt was turned on and utilized frequently due to its importance in initiating the wireless chip functionality (see Wireless Communications Section). | Back to contents |
Transmission of data:
Data transmitted across the UART was sent through multiple series of 1-block or 2-block packets consisting of a start bit, 8(or 16) bits of data, and a stop bit. The UART on all microcontrollers also sent data in least-significant bit (LSB) format. No other available formats such as idle frames, breaks, and IrDA encoding were used for data sending. Data transfer was initiated whenever a byte was transferred into the USCI transfer buffer (TXBUF). Once loaded, the UART sent data to the other device at the specified baud rate. However, despite any successful data transfer, the UART implementation doesn’t utilize acknowledgments to confirm if the other device successfully received the packet. Additionally, the UART was programmed in conjunction with the given protocol (see User Protocol section) by checking the byte it transmits. If the byte that was to be transmitted was a special escape character, the UART would write the data escape symbol and then transmit the respective information. Once transfer was initiated, the UART would continue to transfer more data bytes (if the packet was more than 1 byte) until the entire packet was sent. | Back to contents |
Reception of data:
Similar to the format above, data was received across the UART through multiple series of 1-block packets or 2-block packets. Also, as with the data transmission, no other available formats such as oversampling, automatic baud-rate detection, and IrDA decoding was used for data receiving. Data reception was initiated whenever the UART module detected a long enough falling edge on the wire (wires are active low) being sent from the other device. Glitch suppression supported on the device prevented any cases of false signals. Once reading started, if the UART was ready to receive data, the UART sampled and placed into the USCI receive buffer (RXBUF) the bit it calculated using majority vote, a built-in feature used in the data reading. Once the UART received the packet, the UART would check to see if there was enough room to store the data packet and, if it does, stores it in a temporary location for later wireless ransmission. | Back to contents |