I2C Messages Frequency not right

I am using this shell program:
#!/bin/bash
sudo i2cset -y -r 7 0x20 0x18 0x00
while true
do
sudo i2cset -y -r 7 0x20 0x08 0x02
sleep 0.001
sudo i2cset -y -r 7 0x20 0x08 0x00
sleep 0.001
done
I using it to send a message to a PCA9506. https://pt.mouser.com/ProductDetail/NXP-Semiconductors/PCA9506DGG518?qs=LOCUfHb8d9sIaCSvvyP53w%3D%3D
The messages are arriving and being translated to a GPIO correctly. The problem is that the data rate of the messages is very low (around 40 Hz). I have check it with a oscilloscope. I am using a 40 pin connector on orin, so the i2c bus I am using is i2c bus 7. When I run i2cdetect -y 7 it shows no addresses, which I believe is strange.

I am getting this messages when I run dmesg | grep i2c

i2c i2c-7: Setting clock rate 100000 on next transfer
[91032.968298] tegra-i2c 31c0000.i2c: I2C transfer timed out
[91033.076530] tegra-i2c 31c0000.i2c: I2C transfer timed out
[91033.184254] tegra-i2c 31c0000.i2c: I2C transfer timed out

I could use some help :)

Could you probe the signal to confirm if the device ack for the i2c command.

Thanks

I receive this on terminal:

Value 0x00 written, readback matched
Value 0x02 written, readback matched

I have implemented this code.

#!/bin/bash

sudo i2cset -y -r 7 0x20 0x18 0x00

counter=0
start_time=$(date +%s.%N)

while true
do
sudo i2cset -y -r 7 0x20 0x08 0x02
sleep 0.001
sudo i2cset -y -r 7 0x20 0x08 0x00
sleep 0.001

# Increment the counter for each iteration
((counter++))
((counter++))


# Calculate elapsed time in seconds
current_time=$(date +%s.%N)
elapsed_time=$(echo "$current_time - $start_time" | bc)

# Calculate frequency
frequency=$(bc <<< "scale=2; $counter / $elapsed_time")

# Print the frequency
echo "Frequency: $frequency Hz"
 if [ $(echo "$elapsed_time > 2" | bc) -eq 1 ]; then
 start_time=$(date +%s.%N) 
 counter=0
     echo "In if clause"
fi

done

The output frequency is what I am seeing in the oscilloscope. Something is blocking the output rate.

So, I did the same code in python, and it started working as expected.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.