STM32 I2C Lecture 60 – Exercise: Testing

  • Post author:
  • Post category:Blog

 

Exercise: Testing

 

 


Now let’s test the application implemented in the previous article.

Steps:

1. Open the 003I2CMasterRxString shown in Figure 1.

Figure 1. 003I2CMasterRxString file.

 

2. Download the code into the Arduino board (Figure 2).

Figure 2. Downloading the code into the Arduino board.

 

3. Open the slave code shown in Figure 3.

Figure 3. STM32 slave code.

 

4. Compile the slave code, as shown in Figure 4.

Figure 4. Code compilation.

 

The code is built successfully. You can see in Figure 5, there are no errors, and now the code is error free. But there is one warning called an unused variable.

Figure 5. Results of compilation.

 

5.  To solve that warning, remove the declaration of commandCode and len variable shown in Figure 6.

Figure 6. Removing unused variables.

 

6. Program the chip (Figure 7).

Figure 7. Programming the chip.

 

7.  Go to the Arduino code, then open the serial monitor. On the serial monitor, type lowercase s and send it (Figure 8).

Figure 8. Serial monitor.

 

8. After sending s, you can see that the data is received and printed on the serial monitor (Figure 9). The data length is 26, and “STM32 Slave mode testing..” is the data you got from the STM32 slave.

Figure 9. Received data printed on the serial monitor.

 

9. Open the logic analyzer. Press the start button and start tracing (Figure 10).

Figure 10. Capturing trace on a logic analyzer.

 

10. Open the serial monitor and send lowercase s, as shown in Figure 11 (same as you did in step 7).

Figure 11. Sending s on the serial monitor.

 

Now in Figure 12, you can observe the trace of data received from the STM32 slave.

Figure 12. I2C trace.

 

If the master receives NACK for the address phase, then there will be a problem in the driver file. If you face such an issue, then make sure that the tempreg variable in program the device own address section of the I2C init is initialized to zero (Figure 13). This step is very important. Otherwise, you will end up with programming the wrong address since the tempreg value is updated in the FREQ field configuration.

Figure 13. Program the device own address section of the I2C init function.

 

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.

Leave a Reply