STM32 I2C Lecture 36 – Exercise: Coding Part 3

  • Post author:
  • Post category:Blog

 

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.

Figure 1. Code to print the data to the console using a 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.

Figure 2. Prototype of the function used for semi hosting.

 

2. Include the second and third line code of Figure 1 in the main function.

Figure 3. Making the necessary changes to 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.

Figure 4. Enabling semi hosting.

 

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.

Exercise: Coding Part 3
Figure 5. Code to print the data after the MasterReceiveData API.

 

Exercise: Coding Part 3
Figure 6. Code to insert a null character at the end of the receive buffer (rcv_buf).

 

Go to the Arduino code and change the message to be sent, as shown in Figure 7.

Exercise: Coding Part 3
Figure 7. Message to be sent.

 

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.

Exercise: Coding Part 3
Figure 8. Result of master code compilation.

 

8. Program the chip (Figure 9) in order to see the output.

Exercise: Coding Part 3
Figure 9. Programming the chip.

 

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.

Exercise: Coding Part 3
Figure 10. Results on the console after hitting run.

 

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).

Exercise: Coding Part 3
Figure 11. Results on the console after pressing the user button.

 

Exercise: Coding Part 3
Figure 12. Results on the console after pressing the user button thrice.

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

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.