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.

C6413 I2C无法初始化

项目中需要利用C6413完成一个I2C的串行通讯,用到了I2C 的slave模式。

现在正在用仿真器调试程序,后面是一段I2C初始化函数。运行初始化函数后,用仿真器查看寄存器里的值,发现寄存器里的值还全是0x00000000。

希望获得帮助。最好在提供一个例程。原先函数调用了库里提供的函数,现在直接采用寄存器赋值方式来初始化。

Uint32 I2C_init()

{

//hI2C = I2C_open(I2C_DEV0, I2C_OPEN_RESET);
//I2C_reset(hI2C);
//*(uint32 *)(I2CMDR0) = 0x00006820;

*(uint32 *)(I2CMDR0) &= ~0x20;

*(uint32 *)(I2CPSC0)    = 0x00000015;

*(uint32 *)(I2CCLKL0)  = 0x00000013;

*(uint32 *)(I2CCLKH0) = 0x00000013;

*(uint32 *)(I2CMDR0)  = 0x00006820;

/*
bit15: NACKMOD 0; the last byte set to 1
bit14: FREE 1;
bit13: STT 1; no use
bit12: RSV 0; no use
bit11: STP 1; no use
bit10: MST 0; slave mode
bit 9: TRX 0; receiver mode
bit 8: XA 0; 7 bit address
bit 7: RM 0; no use
bit 6: DLB 0; no use LOOPBACK
bit 5: IRS 1; Enable I2C module
bit 4: STB 0; disable start Byte mode
bit 3: FDF 0; address mode,not free data fomat;
bit 2-0: BC 000; byte count
*/

*(uint32 *)I2COAR0 = 0x0000005A; /*Slave address = 0x5A*/
*(uint32 *)I2CIMR0 = 0x00000000;   /*Disable all interrupt*/

return 0;

}