AW32 IIC 做从机,产生不了中断
首先看一下我计算其分频因子是否有错误:
MCU clock speed: 3706000 Hz Block Module Name Address Range Status 0 FLASH 8000 - FFFF Programmed - Unselected
希望得到100K速率
100 000 = 3706000/(mul*SCL分频数)
当mul = 01时,SCL分频数 = 37.06
查表(Table 13-3. IIC Divider and Hold Values) 当SCL分频数36最接近的,即取ICR = 0X0A SDA的保持时间为9
从而得IIC1F = 0x0A
程序如下,我用已经好的主机通过IIC去访问该从机,为什么就是产生不了中断,进不了IIC_ISR函数
#define DEVICE_I2C_ADR 0x40
void IIC_init(void) { IIC1C = 0x00; //禁止IIC模块 IIC1F = 0x0A; //设成100K IIC1A = DEVICE_I2C_ADR;//设从机地址 IIC1S = 0x12; //状太寄存器 IIC1C = 0xC8; //IIC1C_IICEN = 1; //IIC模块使能 //IIC1C_IICIE = 1; //中断使能 //IIC1C_MST = 0; //IIC模块设为从机 //IIC1C_TXAK = 0; }
interrupt VectorNumber_Viic1 void IIC_ISR(void) { unsigned char dummy_dat; IIC1S_IICIF = 1; //清除中断标志位 if(IIC1C_MST == 0) //是设成从机吗? 不参与仲裁.... { if(IIC1S_IAAS == 1) //从机地址匹配吗? { } else {
} } else //设成主机吗? { } }
|