Null Termination Issue
This week I have been trying to make the read and readstring function working in the simulator.
There are two main problems:
- Read function can only return the same data byte every time it is called. For example, when a string “HELLO” is written to the data register, read function can only return the last character of the string, which is ‘O’ or 79 in ASCII.
- Readstring function continued to read each byte of data without stopping. This is because there is no null terminator detected, causing the while loop unable to be terminated.
For second problem, I need to insert a null terminator every time a string is written to the data register. This can be done easily from the writestring function. The function will write a null terminator at the end of string, allowing the readstring function to terminate the read character loop when detects the null terminator.
After solving these two problems, I started to start working on the I2C (Inter-Integrated Circuit) module by studying the structure and its working principle.
That’s all for this week