This week I am working with UART (Universal asynchronous receiver/transmitter). UART is a device that used for serial communication over a peripheral device serial port or computer. UART takes bytes of data and transmits the individual bits in a sequential fashion. UART consists of a data bus with several data lines (usually 8) with control pins for read/write and two serial wires which are TX (Transmit) and RX (Receive). Note that the connection between UART must be carefully and correctly connected. TX pin must be connected with the device’s RX pin and vice versa.

To start with UART, I read about how UART transmit and receive data. Also, I take Arduino’s Serial library as reference to work with UART in the simulator. For UART module in simulator, I created functions to read and write data. Function ‘read()’ will be able to read the first byte of incoming available data. Note that UART handles data based on FIFO (first in first out) method where the first data entry is always processed first.

To transmit data to a device, I created function ‘write()’. This function will be able to send a byte or series of bytes of data. The value returned by this function is the number of bytes written. The write() function can take in any types of input (integers, characters and even array of characters).

Other than these two functions, I also created functions such as peek() and ReadString(). peek() returns the next byte of incoming data without removing it. In other words, it will return the same character, as will the next call to read(). ReadString() will reads character and stores into a string and return it. Currently I am trying to fix some errors found when calling these two functions. Instead of using string, I used char pointer to return the array of characters, which is inappropriate. Next week I will try to figure out the correct way to do it. That is all for this week.