请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号: TMAG3001EVM
EVM 的该示例代码是变量 Address_Select、但没有定义。
请您对此发表评论。
uint8_t TMAG3001calculateCRC(uint8_t i2cRead, uint8_t numChannels, uint8_t data[])
{
if ((i2cRead > 0x02) || (numChannels == 0) || (numChannels > 0x04)) assert(1 == 0);
int i = 0;
uint8_t crc = 0xFF;
uint8_t crcNew = 0x00;
uint8_t d[8];
uint8_t c[8];
int j = 0;
if (i2cRead == 0x01) numChannels = (numChannels * 2) + 2;
else if (i2cRead == 0x02) numChannels = (numChannels + 2);
else numChannels = 4;
for (i = 0; i < numChannels; i++)
{
for (j = 0; j < 8; j++)
{
if (i2cRead != 0x00)
{
if (i == 0) d[j] = (((Address_Select << 1) | 1) >> j) & 0x01;
else d[j] = (data[i - 1] >> j) & 0x01;
}
else d[j] = (data[i] >> j) & 0x01;
c[j] = (crc >> j) & 0x01;
}
crcNew = d[7] ^ d[6] ^ d[0] ^ c[0] ^ c[6] ^ c[7];
crcNew |= (d[6] ^ d[1] ^ d[0] ^ c[0] ^ c[1] ^ c[6]) << 1;
crcNew |= (d[6] ^ d[2] ^ d[1] ^ d[0] ^ c[0] ^ c[1] ^ c[2] ^ c[6]) << 2;
crcNew |= (d[7] ^ d[3] ^ d[2] ^ d[1] ^ c[1] ^ c[2] ^ c[3] ^ c[7]) << 3;
crcNew |= (d[4] ^ d[3] ^ d[2] ^ c[2] ^ c[3] ^ c[4]) << 4;
crcNew |= (d[5] ^ d[4] ^ d[3] ^ c[3] ^ c[4] ^ c[5]) << 5;
crcNew |= (d[6] ^ d[5] ^ d[4] ^ c[4] ^ c[5] ^ c[6]) << 6;
crcNew |= (d[7] ^ d[6] ^ d[5] ^ c[5] ^ c[6] ^ c[7]) << 7;
crc = crcNew;
}
return crc;
}
在另一个代码中、延迟为 200ms。 什么是 th eason? 这也可以消除吗?
void TMAG3001restoreDefaultValues()
{
int i = 0;
uint8_t defaultRegisters[NUM_REGISTERS] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x49, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00 };
for(i = 0; i < NUM_REGISTERS; i++)
{
TMAG3001writeToSingleRegister(i, defaultRegisters[i]);
delay_us(200000);
}
}