Control Box (part 5) Serial Communication and the UART Module

The time has now come to send the results of our previous calculations to the underwater ROV. The method by which we will do so is through the use of the PIC's UART module. This module uses to RS232 serial protocol to both send and receive data between devices. It is an asynchronous protocol and therefore does not require the use of a synchronizing clock.

Configuring the UART module

We begin by configuring the UART module for both transmission and reception and set the baud rate with the code below (Which is found in the init.asm file.) Additionally, UART reception interrupts are enabled.

code screenshot

code screenshot

With the UART module configured, we are now able to use it to send data packets below surface. You will notice that the main loop and interrupt routine both update the variables state, forwardSpeed, reverseSpeed and upDownSpeed as necessary depending on the branching of the program. Once these values have been calculated, the subroutine "sendThrust" is called. The "sendThrust" subroutine can be found in the uart.asm file and is shown below:

code screenshot

The 5ms delay between packets has been added for testing purposes (and later removed/shortened) to allow for a distinct visual break in between each transmission when viewing the signal with an oscilloscope or logic analyzer. For each packet transmission, the data is placed into a variable/memory location named "transData" just before calling the subroutine "Transmit". The "Transmit" routine is also found in the uart.asm file and is also shown below:

code screenshot

Once "transData" is loaded into TXREG, it is automatically shifted into the TSR register by the hardware and then pushed out onto the UART transmit pin (labeled TX/pin #25). The packet is now effectively on it's way to the ROV. Before exiting the "Transmit" subroutine, we poll the TXIF flag of the PIR1 register. As long as this bit is set, there is still data in the buffer waiting to be shifted out. If we were to exit the routine and send more data before the buffer was empty, packet corruption would result. Once the flag is clear, we exit this "wait_trans loop and then exit the subroutine."


Additionally, the uart.asm file contains a subroutine for receiving data via the UART module. Such received data will be related to sensors and indicator signals sent from the ROV and while we haven't covered those things yet, I will briefly explain how we get this data when it is sent. The subroutine is shown below:

code screenshot

So with all of the above accomplished, we have more or less configured our control box MCU to:

  1. Perform and AD conversion from the joystick input.
  2. Convert the results from the AD conversion to values to be utilized by the ROV microcontroller.
  3. Send these results to the sub-surface ROV via UART.
  4. Receive any data packets from the ROV via UART.

Next we will begin to discuss the LCD panel and the various messages it displays.

Next up, LCD display