主题中讨论的其他器件:MCT8316A、
它会一直正常运行、直到您注册、发送和检查寄存器。 我们还将其修改为芯片 ID 0x60。 但是、校验和语法中出现错误。 似乎是针对其他芯片进行了编程优化。 您能否检查数据传送声明或 EEPROM 访问寄存器是否正确?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
我希望您能玩得开心。 我写这封信是为了补充其他问题。
1.我想请您确认 I2C_WRITE 语法中的0xE6寄存器是否正确。
if (!I2C_write(0xE6, 0x8A500000, I2C_TIMEOUT)) prog_error = true; __delay_cycles(2000000); // delay at least 100ms for copy operation from Shadow-register to EEPROM to complete __no_operation(); // For setting breakpoint while debugging /* Set the EEPROM_READ bit in the DEV_CTRL register (0xEA located in RAM * This copies the content of the EEPROM memory back into the shadow registers */ if (!I2C_write(0xE6, 0x40000000, I2C_TIMEOUT)) prog_error = true; __delay_cycles(2000000); // delay at least 100ms for copy operation from EEPROM to Shadow-register to complete __no_operation(); // For setting breakpoint while debugging
2.我已检查数据是否被读写。 但是、校验和部分存在错误。 您能帮助我更正此部分吗?
for (i = 0; i < eeprom_array_size; i++)
{
if(!I2C_read(eeprom_regmap[i][0], &(post_eeprom_write_regs[i]), I2C_TIMEOUT))
{
prog_error = true;
break;
}
if (post_eeprom_write_regs[i] != eeprom_regmap[i][1])
{
prog_error = true;
//GPIO_setOutputHighOnPin(GPIO_PORT_P6, GPIO_PIN6);
//GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);
break;
}尊敬的 Yongma:
1. 我想请您确认 I2C_WRITE 语法中的0xE6寄存器正确。
所提供代码中的语法看起来正确。
2. 我已检查数据是否已写入和读取。 但是、校验和部分存在错误。 您能否帮助我更正此器件?
在提供的代码中的第9行之前、您能否 通过将两个数组都打印出来或通过另一种方法来检查数组的内容、并检查数组中的差异所在?
此致、
约书亚
1.我无法检查。 您能告诉我如何通过 UART 或其他方法进行检查吗?
2.查看数据表、发现 MCT8316A 与 MCT8329A 和写入操作数据包似乎不同。 应如何更改此器件?
bool I2C_write(unsigned long addr, unsigned long writedata, uint32_t timeout) {
EUSCI_B_I2C_initMasterParam param = {0};
param.selectClockSource = EUSCI_B_I2C_CLOCKSOURCE_SMCLK;
param.i2cClk = CS_getSMCLK();
param.dataRate = EUSCI_B_I2C_SET_DATA_RATE_400KBPS;
param.byteCounterThreshold = 0;
param.autoSTOPGeneration = UCASTP_0;
EUSCI_B_I2C_initMaster(EUSCI_B1_BASE, ¶m);
//Enable I2C Module to start operations
EUSCI_B_I2C_enable(EUSCI_B1_BASE);
// Construct the 24 bit control word (refer to datasheet section 7.6.2.1)
char control_word[3] = {0x10, (addr&0x00000F00)>>8, addr&0x000000FF};
/* Set slave Address */
EUSCI_B_I2C_setSlaveAddress(EUSCI_B1_BASE,
I2C_TARGET_ADDR
);
/* Set master to transmit mode */
EUSCI_B_I2C_setMode(EUSCI_B1_BASE,
EUSCI_B_I2C_TRANSMIT_MODE);
EUSCI_B_I2C_masterSendStart(EUSCI_B1_BASE);
__delay_cycles(INTER_BYTE_DELAY);
/* Send bits CW23-CW16 of the control word */
if (!EUSCI_B_I2C_masterSendMultiByteNextWithTimeout(EUSCI_B1_BASE, control_word[0], timeout))
return 0;
__delay_cycles(INTER_BYTE_DELAY);
/* Send bits CW15-CW8 of the control word */
if (!EUSCI_B_I2C_masterSendMultiByteNextWithTimeout(EUSCI_B1_BASE, control_word[1], timeout))
return 0;
__delay_cycles(INTER_BYTE_DELAY);
/* Send bits CW7-CW0 of the control word */
if (!EUSCI_B_I2C_masterSendMultiByteNextWithTimeout(EUSCI_B1_BASE, control_word[2], timeout))
return 0;
__delay_cycles(INTER_BYTE_DELAY);
/* Send D7-D0 of the 32-bit data */
if (!EUSCI_B_I2C_masterSendMultiByteNextWithTimeout(EUSCI_B1_BASE, writedata & 0x000000FF, timeout))
return 0;
__delay_cycles(INTER_BYTE_DELAY);
/* Send D15-D8 of the 32-bit data */
if (!EUSCI_B_I2C_masterSendMultiByteNextWithTimeout(EUSCI_B1_BASE, (writedata & 0x0000FF00)>>8, timeout))
return 0;
__delay_cycles(INTER_BYTE_DELAY);
/* Send D23-D16 of the 32-bit data */
if (!EUSCI_B_I2C_masterSendMultiByteNextWithTimeout(EUSCI_B1_BASE, (writedata & 0x00FF0000)>>16, timeout))
return 0;
__delay_cycles(INTER_BYTE_DELAY);
/* Send D31-D23 of the 32-bit data */
if (!EUSCI_B_I2C_masterSendMultiByteNextWithTimeout(EUSCI_B1_BASE, (writedata & 0xFF000000)>>24, timeout))
return 0;0000000
__delay_cycles(INTER_BYTE_DELAY);
EUSCI_B_I2C_masterSendMultiByteStop(EUSCI_B1_BASE);
return 1;
}我解决了,代码没有问题,谢谢你的回答。
首先、我希望您更改目标 ID、使其保持在0x60。
第一次写入时、目标 ID 为0x60、第二次写入时为0x00。 (数据表7.6.1.1、表7-7)
我会给那些将会对我来说是新的人留下一篇文章。
1.更改目标 ID (0x60或0x00、main.c-51行)
2.更改影子寄存器值(0xE6、main.c - 153,162行)
3.寄存器映射中仅放置数据表中写入的24项。 (8329A 有39个 GUI。)