588 字
3 分钟
address_calculate
记录一次芯片的地址计算
地址介绍
前几天刚发了一篇ltc2497的六层板绘制过程,这两天准备写它的驱动,奈何芯片比较小众只能自己写(练习一下)
先看他的地址列表
// #define LTC2497_I2C_ADDRESS 0x14 // Low Low Low
// #define LTC2497_I2C_ADDRESS 0x16 // Low Low High
// #define LTC2497_I2C_ADDRESS 0x15 // Low Low Float
// #define LTC2497_I2C_ADDRESS 0x26 // Low High Low
// #define LTC2497_I2C_ADDRESS 0x34 // Low High High
// #define LTC2497_I2C_ADDRESS 0x27 // Low High Float
// #define LTC2497_I2C_ADDRESS 0x17 // Low Float Low
// #define LTC2497_I2C_ADDRESS 0x25 // Low Float High
// #define LTC2497_I2C_ADDRESS 0x24 // Low Float Float
// #define LTC2497_I2C_ADDRESS 0x56 // High Low Low
// #define LTC2497_I2C_ADDRESS 0x64 // High Low High
// #define LTC2497_I2C_ADDRESS 0x57 // High Low Float
// #define LTC2497_I2C_ADDRESS 0x74 // High High Low
// #define LTC2497_I2C_ADDRESS 0x76 // High High High
// #define LTC2497_I2C_ADDRESS 0x75 // High High Float
// #define LTC2497_I2C_ADDRESS 0x65 // High Float Low
// #define LTC2497_I2C_ADDRESS 0x67 // High Float High
// #define LTC2497_I2C_ADDRESS 0x66 // High Float Float
// #define LTC2497_I2C_ADDRESS 0x35 // Float Low Low
// #define LTC2497_I2C_ADDRESS 0x37 // Float Low High
// #define LTC2497_I2C_ADDRESS 0x36 // Float Low Float
// #define LTC2497_I2C_ADDRESS 0x47 // Float High Low
// #define LTC2497_I2C_ADDRESS 0x55 // Float High High
// #define LTC2497_I2C_ADDRESS 0x54 // Float High Float
// #define LTC2497_I2C_ADDRESS 0x44 // Float Float Low
// #define LTC2497_I2C_ADDRESS 0x46 // Float Float High
// #define LTC2497_I2C_ADDRESS 0x45 // Float Float Float
看起来很复杂,貌似没有规律
地址计算
刚开始我也没看出来,然后我把它放到万能的excel中排了一下序列,结果如下
(第一排是16进制,缺了 0x 不要介意)
规律如下:
- 第一排的第一个数字,也就是地址前四位依次为1-7
- 第二排都为4-7
- low < float < high
是不是发现了规律
本质上就是三进制转为8进制+4进制再加一个基地址0x14
程序编写验证
拿clion新建了个工程试一下
void set_ltc2497_adress(uint8_t addr2,uint8_t addr1, uint8_t addr0)
{
//auto calculate the address
uint8_t num = 0x00;
num = addr2*9 + addr1*3 + addr0*1;
num = ((num/4) << 4)|(num%4);
num = num + 0x14;
std::cout << "address: " << "0x" << std::hex << int(num) << std::endl;
}
int main()
{
//输出全部地址
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
for (int k = 0; k < 3; k++)
{
set_ltc2497_adress(i, j, k);
}
}
}
system("pause");
return 0;
return 0;
}
输出结果如下
address: 0x14
address: 0x15
address: 0x16
address: 0x17
address: 0x24
address: 0x25
address: 0x26
address: 0x27
address: 0x34
address: 0x35
address: 0x36
address: 0x37
address: 0x44
address: 0x45
address: 0x46
address: 0x47
address: 0x54
address: 0x55
address: 0x56
address: 0x57
address: 0x64
address: 0x65
address: 0x66
address: 0x67
address: 0x74
address: 0x75
address: 0x76
至此,结束
address_calculate
https://f.undf.top/posts/post/code/embedded/address_calculate/