void I2C2_EV_IRQHandler(void) { u8 temp; u8 IIC_LEN; u8 i; u8 IIC_STRSUM; switch (I2C_GetLastEvent(I2C2)) { case I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED: { IIC_SENDNUMB=0; //I2C2->DR=IIC_SLAVE_SENDBUF[IIC_SENDNUMB]; I2C_SendData(I2C2,IIC_SLAVE_SENDBUF[IIC_SENDNUMB]); // while(I2C2->SR2&0x0040); IIC_SENDNUMB++; IIC_SENDFLAG=1; };break; case I2C_EVENT_SLAVE_BYTE_TRANSMITTED: { //I2C2->DR=IIC_SLAVE_SENDBUF[IIC_SENDNUMB]; I2C_SendData(I2C2,IIC_SLAVE_SENDBUF[IIC_SENDNUMB]); // while(I2C2->SR2&0x0040); IIC_SENDNUMB++; IIC_SENDFLAG=1; break; } case I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED: { IIC_RECENUMB=0; temp=I2C_ReceiveData(I2C2); break; } case I2C_EVENT_SLAVE_BYTE_RECEIVED: { //IIC_RECEFLAG=1; temp=I2C_ReceiveData(I2C2); switch (IIC_SLAVE_STEP) { case 0:{ if(temp==0xfa) { // IIC_RECEFLAG=1; IIC_SLAVE_RECBUF[IIC_RECENUMB]=temp; IIC_RECENUMB++; IIC_SLAVE_STEP++; //IIC_RECEFLAG=1; } };break; case 1:{ if((temp==0xb0)||(temp==0xb1)||(temp==0xb2)||(temp==0xb3)||(temp==0xb4) ||(temp==0xb5)||(temp==0xb6)||(temp==0xb8)||(temp==0xbe)||(temp==0xbf) ||(temp ==0xba)||(temp==0xbd)||(temp==0xbb)||(temp==0xaa)||(temp == 0xb9) ||(temp == 0xb7)||(temp ==0xbc)||(temp==0xd0)) { // IIC_RECEFLAG=1; if((temp == 0xb0)||(temp == 0xb2)||(temp == 0xb4)||(temp == 0xbe) ||(temp == 0xbb)||(temp == 0xb9)||(temp == 0xb7)||(temp==0xd0)) // 11.1增加故障转运行 { IIC_WILL_GET_LEN = 4; } else if ((temp == 0xb1 )||(temp == 0xb3)||(temp == 0xb5)||(temp == 0xb6) ||(temp == 0xb8)||(temp == 0xbf)||(temp == 0xba)||(temp == 0xbc)) //11.1增加确认故障转运行 { IIC_WILL_GET_LEN = 8; } else if (temp ==0xbd) { IIC_WILL_GET_LEN =5; } IIC_SLAVE_RECBUF[IIC_RECENUMB]=temp; IIC_RECENUMB++; IIC_SLAVE_STEP++; } else { IIC_RECENUMB=0; } };break; case 2:{ if((temp==0xf5)&&(IIC_RECENUMB==(IIC_WILL_GET_LEN-1))) { IIC_SLAVE_RECBUF[IIC_RECENUMB]=temp; IIC_RECENUMB++; IIC_LEN=IIC_RECENUMB-2; IIC_STRSUM=0; for(i=1;iCR1&=0xffff; };break; default:break; } 麻烦帮我看看I2C中断发送有没有问题,不能连续发送啊~!!! |
RE:IIC SLAVE 问题
{
I2C_InitTypeDef I2C_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
GPIO_Init(GPIOB, &GPIO_InitStructure);
I2C_DeInit(I2C2);
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = 0xc0;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = I2C_Speed;
I2C_Cmd(I2C2, ENABLE);
I2C_Init(I2C2, &I2C_InitStructure);
}
这个是IIC初始化程序。
RE:IIC SLAVE 问题
for(;;)
{
/*
for(z=0;z
RE:IIC SLAVE 问题,请管理员和版主关注下,谢谢哦~