Exercise: Testing
Now let’s test the application implemented in the previous article.
Steps:
1. Open the 003I2CMasterRxString shown in Figure 1.
2. Download the code into the Arduino board (Figure 2).
3. Open the slave code shown in Figure 3.
4. Compile the slave code, as shown in Figure 4.
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.
5. To solve that warning, remove the declaration of commandCode and len variable shown in Figure 6.
6. Program the chip (Figure 7).
7. Go to the Arduino code, then open the serial monitor. On the serial monitor, type lowercase s and send it (Figure 8).
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.
9. Open the logic analyzer. Press the start button and start tracing (Figure 10).
10. Open the serial monitor and send lowercase s, as shown in Figure 11 (same as you did in step 7).
Now in Figure 12, you can observe the trace of data received from the STM32 slave.
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.