This week Dr Shawn has explained to me the internal registers of UART, SPI and TWI. Basically these modules has two registers: status register and data register. Status register, from its name we know that this register contains information about the state of the device. Data register contains the data to be stored or to be fetched.
For each module, I need to implement flags to check the status of the device whether it is ready to perform data transmission or receive data from other device.
The status register is checked frequently until the device is ready. In this case, Dr Shawn introduced to me the polling method. Polling is the process to check for a device’s readiness or state. In programming, the polling can be implemented by using while-loop or for-loop to continuously check the status register. However, while-loop is not recommended as it might result in an infinite loop. Therefor it is better to use for-loop with a timeout variable which will exit the loop after reaching the timeout condition.
Polling is often used in low-level devices such as printers. If there are too many devices to check, the time required to poll them can exceed the time available to service the I/O device.
The next part is dealing with the functions to read data from or write data to data register. Uart consists of simple read and write function, and read string and write string functions as well. I am having hard time in coding the read/write string function due to poor understanding in c-string. So, currently I am trying hard to study c-string fundamentals and find out what went wrong. Hopefully I can get the job done asap. That’s all for this week.
0 Comments