Exercise: Coding Part 3
Use of semi hosting to print the data to the console:
You have to use the code shown in Figure 1 to print the data to the console using the semi hosting method.
Steps to print the data to the console using semi hosting method is as follows:
1. Do the extern of the function given in Figure 1 in the application: Copy the function in Figure 1, then go to the application and paste it, as shown in Figure 2.
2. Include the second and third line code of Figure 1 in the main function.
3. Go to your driver’s debug configuration, select the startup option, and ensure that you have enabled semi hosting in the run commands. If not, then enable it by using the monitor arm semi hosting enable command, as shown in Figure 4.
4. Print the data after the MasterReceiveData API (Figure 5) since the data is received in the MasterReceiveData API.
Remember that the receive buffer (rcv_buf) is not terminated with the null character because we don’t receive the null character from the slave in the transmission. But if you use %s while printing the data, then the rcv_buf has to be terminated with the null character. So, give the null character at the end of the rcv_buf, as shown in Figure 6.
Go to the Arduino code and change the message to be sent, as shown in Figure 7.
5. Compile the Arduino Code by pressing the verify button.
6. Download the code into the board by pressing the upload button.
7. Compile the master code to check whether there are any errors. In Figure 8, you can see that there are no errors.
8. Program the chip (Figure 9) in order to see the output.
9. Go to the debug mode to see the output. In the debug mode, remove all the breakpoints if there is any.
10. Hit the run.
11. In Figure 10, you can see that the application is running.
12.Press the user button. After pressing the button, the data will be printed on the console, as shown in Figure 11. Each time when you press the user button, the data will be printed on the console (Figure 12).
If you don’t have the logic analyzer to see the output, then you can use the semi hosting method.
In the following article, let’s test the reapeated start.
FastBit Embedded Brain Academy Courses,
Click here: https://fastbitlab.com/course1