Notes14ADS7830
Posted 码农编程录
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Notes14ADS7830相关的知识,希望对你有一定的参考价值。
1.读ADS7830的8个channel电压:i2c-test -b 7 -s 0x71 -w -d 0x04
如下1000 1100为六进制0x8c,十进制140。
如下从SD=1往下看,SD=0不用看。
cmd | (((ch >> 1) | (ch & 0x01) << 2) << 4); cmd =0x8c。
i2c-test -b 7 -s 0x48 -rc 1 -d 0x8c #显示十六进制0x57即十进制87。如下x=87*9766,divisor=1000。
#define DIV_ROUND_CLOSEST(x, divisor)({ //C文件
typeof(x) __x = x;
typeof(divisor) __d = divisor;
(((typeof(x))-1) > 0 ||
((typeof(divisor))-1) > 0 ||
(((__x) > 0) == ((__d) > 0))) ?
(((__x) + ((__d) / 2)) / (__d)) :
(((__x) - ((__d) / 2)) / (__d));
})
# Read_ADS7830_0x48_Voltage.sh
#!/bin/bash
DIV_ROUND_CLOSEST(){
__x=$1
__d=$2
A=$(((__x) > 0))
B=$(((__d) > 0))
C=$(($__d>>1))
C=$(($__x+$C))
C=$(($C/$__d))
D=$(($__d>>1))
D=$(($__x+$D))
D=$(($D/$__d))
E=$(($A==$B))
echo $(($E?$C:$D))
}
stop_ipmistack()
{
cnt=0
while true
do
/etc/init.d/ipmistack stop >/dev/null 2>&1
s1=$(ps aux)
s2="/usr/local/bin/IPMIMain"
result=$(echo $s1 | grep "${s2}")
if [[ "$result" == "" ]]
then
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to stop ipmistack !"
exit 1
fi
cnt=$(($cnt+1))
sleep 10
done
}
delete()
{
cnt=0
while true
do
echo 0x73 > /sys/bus/i2c/devices/i2c-7/delete_device
if [ $? = 0 ]
then
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to delete device !"
exit 1
fi
cnt=$(($cnt+1))
done
}
access()
{
cnt=0
while true
do
i2c-test -b 7 -s 0x73 -w -d 0x08 >/dev/null 2>&1
if [ $? = 0 ]
then
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to access 9545 !"
exit 1
fi
cnt=$(($cnt+1))
echo $cnt
done
}
OpenChannel()
{
cnt=0
while true
do
i2c-test -b 7 -s 0x71 -w -d 0x04 >/dev/null 2>&1
if [ $? = 0 ]
then
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to access 9548 channel 3 !"
exit 1
fi
cnt=$(($cnt+1))
done
}
read_channel0(){
cnt=0
while true
do
val_0=$(i2c-test -b 7 -s 0x48 -rc 1 -d 0x8c)
if [ $? = 0 ]
then
#echo $val_0
hex_0=${val_0:34:2}
#echo $hex_0 #57
dec_0=$((0x$hex_0 & 0xff))
#echo $dec_0 #87
dec_v_0=$((dec_0*9766))
dec_v_v_0=$(DIV_ROUND_CLOSEST $dec_v_0 1000)
echo "ADS7830 CH0:PFM8_VCC Voltage : "$dec_v_v_0"mV"
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to read channel0 voltage !"
exit 1
fi
cnt=$(($cnt+1))
done
}
read_channel1(){
cnt=0
while true
do
val_1=$(i2c-test -b 7 -s 0x48 -rc 1 -d 0xcc)
if [ $? = 0 ]
then
hex_1=${val_1:34:2}
#echo $hex_1
dec_1=$((0x$hex_1 & 0xff))
#dec_1=printf("%d\\n",hex_1)
#echo $dec_1
dec_v_1=$((dec_1*9766))
dec_v_v_1=$(DIV_ROUND_CLOSEST $dec_v_1 1000)
echo "ADS7830 CH1:P1V8_FM Voltage : "$dec_v_v_1"mV"
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to read channel1 voltage !"
exit 1
fi
cnt=$(($cnt+1))
done
}
read_channel2(){
cnt=0
while true
do
val_2=$(i2c-test -b 7 -s 0x48 -rc 1 -d 0x9c)
if [ $? = 0 ]
then
hex_2=${val_2:34:2}
#echo $hex_2 #57
dec_2=$((0x$hex_2 & 0xff))
#echo $dec_2
dec_v_2=$((dec_2*9766))
dec_v_v_2=$(DIV_ROUND_CLOSEST $dec_v_2 1000)
echo "ADS7830 CH2:P0V6_VTT_CH01 Voltage : "$dec_v_v_2"mV"
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to read channel2 voltage !"
exit 1
fi
cnt=$(($cnt+1))
done
}
read_channel3(){
cnt=0
while true
do
val_3=$(i2c-test -b 7 -s 0x48 -rc 1 -d 0xdc)
if [ $? = 0 ]
then
#echo 3
#echo $val_3
hex_3=${val_3:34:2}
#echo $hex_3 #57
dec_3=$((0x$hex_3 & 0xff))
#echo $dec_3 #
dec_v_3=$((dec_3*9766))
dec_v_v_3=$(DIV_ROUND_CLOSEST $dec_v_3 1000)
echo "ADS7830 CH3:P0V6_VTT_CH23 Voltage : "$dec_v_v_3"mV"
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to read channel3 voltage !"
exit 1
fi
cnt=$(($cnt+1))
done
}
read_channel4(){
cnt=0
while true
do
val_4=$(i2c-test -b 7 -s 0x48 -rc 1 -d 0xac)
if [ $? = 0 ]
then
#echo 4
#echo $val_4
hex_4=${val_4:34:2}
#echo $hex_4 #57
dec_4=$((0x$hex_4 & 0xff))
#echo $dec_4
dec_v_4=$((dec_4*9766))
dec_v_v_4=$(DIV_ROUND_CLOSEST $dec_v_4 1000)
echo "ADS7830 CH4:P1V8_VCCFUSEWR_SDM Voltage : "$dec_v_v_4"mV"
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to read channel4 voltage !"
exit 1
fi
cnt=$(($cnt+1))
done
}
read_channel5(){
cnt=0
while true
do
val_5=$(i2c-test -b 7 -s 0x48 -rc 1 -d 0xec)
if [ $? = 0 ]
then
#echo 5
#echo $val_5
hex_5=${val_5:34:2}
#echo $hex_5 #57
dec_5=$((0x$hex_5 & 0xff))
#echo $dec_5
dec_v_5=$((dec_5*9766))
dec_v_v_5=$(DIV_ROUND_CLOSEST $dec_v_5 1000)
echo "ADS7830 CH5:P1V8_IO Voltage : "$dec_v_v_5"mV"
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to read channel5 voltage !"
exit 1
fi
cnt=$(($cnt+1))
done
}
read_channel6(){
cnt=0
while true
do
val_6=$(i2c-test -b 7 -s 0x48 -rc 1 -d 0xbc)
if [ $? = 0 ]
then
#echo 6
hex_6=${val_6:34:2}
#echo $hex_6 #57
dec_6=$((0x$hex_6 & 0xff))
#echo $dec_6 #
dec_v_6=$((dec_6*9766))
dec_v_v_6=$(DIV_ROUND_CLOSEST $dec_v_6 1000)
echo "ADS7830 CH6:P0V8_VCCL_SDM Voltage : "$dec_v_v_6"mV"
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to read channel6 voltage !"
exit 1
fi
cnt=$(($cnt+1))
done
}
read_channel7(){
cnt=0
while true
do
val_7=$(i2c-test -b 7 -s 0x48 -rc 1 -d 0xfc)
if [ $? = 0 ]
then
#echo $val_7
hex_7=${val_7:34:2}
#echo $hex_7 #57
dec_7=$((0x$hex_7 & 0xff))
#echo $dec_7 #
dec_v_7=$((dec_7*9766))
dec_v_v_7=$(($(DIV_ROUND_CLOSEST $dec_v_7 1000)*2))
echo "ADS7830 CH7:P3V3_EARLY Voltage : "$dec_v_v_7"mV"
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to read channel7 voltage !"
exit 1
fi
cnt=$(($cnt+1))
done
}
start_ipmistack()
{
cnt=0
while true
do
/etc/init.d/ipmistack start >/dev/null 2>&1
s1=$(ps aux)
s2="/usr/local/bin/IPMIMain"
result=$(echo $s1 | grep "${s2}")
if [[ "$result" != "" ]]
then
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to start ipmistack !"
exit 1
fi
cnt=$(($cnt+1))
sleep 10
done
}
start_ipmistack
stop_ipmistack
delete
access
OpenChannel
read_channel0
read_channel1
read_channel2
read_channel3
read_channel4
read_channel5
read_channel6
read_channel7
start_ipmistack
以上是关于Notes14ADS7830的主要内容,如果未能解决你的问题,请参考以下文章
在 header.php 文件的 php 命令中添加 Google Ads 事件片段
Note3MPS/PXE/ADS/INA电流电压芯片,i2c设备在位和读访问,FPGA版本,PCIE读写,TMP112,Fan转速,uuid库
iOS 14 之后 Firebase 中的 Apple Search Ads 广告系列归因
VSCode自定义代码片段14——Vue的axios网络请求封装