我现在用MIN51做I2C的从设备,用中断来读主设备数据,参考了官网里面有个例程(I2C_Software_GPIO),但是原程序里面里面设了四个设备地址,我的设备地址是0xa0,要怎么设置啊?
/* Set I2C 4 Slave Addresses */
I2C_SetSlaveAddr(I2C, 0, 0x15, 0); /* Slave Address : 0x15 */
I2C_SetSlaveAddr(I2C, 1, 0x35, 0); /* Slave Address : 0x35 */
I2C_SetSlaveAddr(I2C, 2, 0x55, 0); /* Slave Address : 0x55 */
I2C_SetSlaveAddr(I2C, 3, 0x75, 0); /* Slave Address : 0x75 */
请问为什么要设四个从设备地址啊?还有作为从设备难道也要设置时钟吗?
/* Open I2C module and set bus clock */
I2C_Open(I2C, 120);
我现在怎么设置都进不了中断,各路高手请指点一下,急盼大侠回复。
下面是中断程序(例程没有改动):
void I2C_IRQHandler(void)
{
uint32_t u32Status;
u32Status = I2C_GET_STATUS(I2C);
switch(u32Status)
{
/* Slave Transmitter Mode */
case 0xC0: /* DATA has been transmitted and NACK has been returned */
case 0xC8: /* DATA has been transmitted and ACK has been returned */
I2C_SET_CONTROL_REG(I2C, I2C_SI | I2C_AA);
printf("Slave Transmitter Success\n");
break;
case 0xA8: /* SLA+R has been received and ACK has been returned */
case 0xB0:
DataLen = 0;
case 0xB8: /* DATA has been transmitted and ACK has been returned */
I2C_SET_DATA(I2C, Tx_Data[DataLen++]);
if(DataLen<sizeof(Tx_Data))
I2C_SET_CONTROL_REG(I2C, I2C_SI | I2C_AA);
else
I2C_SET_CONTROL_REG(I2C, I2C_SI);
break;
/* Slave Receiver Mode*/
case 0x68: /* SLA+W has been received and ACK has been returned */
case 0x60:
DataLen = 0;
Rx_Data[0] = 0;
I2C_SET_CONTROL_REG(I2C, I2C_SI | I2C_AA);
break;
case 0x80: /* DATA has been received and ACK has been returned */
Rx_Data[DataLen++] = I2C_GET_DATA(I2C);
if(DataLen<(sizeof(Rx_Data)-1))
I2C_SET_CONTROL_REG(I2C, I2C_SI | I2C_AA);
else
I2C_SET_CONTROL_REG(I2C, I2C_SI);
break;
case 0x88: /* DATA has been received and NACK has been returned */
Rx_Data[DataLen++] = I2C_GET_DATA(I2C);
I2C_SET_CONTROL_REG(I2C, I2C_SI | I2C_AA);
break;
case 0xA0: /* STOP or Repeat START has been received */
I2C_SET_CONTROL_REG(I2C, I2C_SI | I2C_AA);
printf("Slave Receiver Success\n");
break;
}
}
|