This week I have been trying to make the read and readstring function working in the simulator.

There are two main problems:

  1. 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.
  2. 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.

The first problem occurred because the string is written to the register by storing each character separately. As a result, the previous data was overwritten when a new character is stored. My solution for this is creating an array as a buffer in the JavaScript and store the data into it. When read function is called, the data is returned based on FIFO method, where the first data element of the array is returned first.

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


0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.