请教原子哥,STM32的ACK这个信号我一直收不到是为什么呢,我是硬件IIC1,读PCF8563芯片,但是没有办法收到那个ACK信号
void I2C_Mode_config(void)
{
I2C_InitTypeDef I2C_InitStructure;//?¨??I2C?á????
//?ò??I2C1?±??
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE);
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;//????I2C??I2C????
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;//?????????ì???¤×÷?????????§
I2C_InitStructure.I2C_OwnAddress1 =0x0A;//???è???·
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable ;//????????
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;//ATC24C02???·??7??
I2C_InitStructure.I2C_ClockSpeed = 400000;//×?????400KHz
I2C_Cmd(I2C1, ENABLE);//????I2C
I2C_Init(I2C1, &I2C_InitStructure);
}
unsigned char i2c_write_n_bytes(unsigned char SLA_W, unsigned int ADDR,unsigned int N, unsigned char *DAT)
{
unsigned int i;
I2C_GenerateSTART(I2C1, ENABLE);//?ú?ú??????
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); //
I2C_Send7bitAddress(I2C1, SLA_W, I2C_Direction_Transmitter);//
I2C_EE_WaitEepromStandbyState();
while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
I2C_SendData(I2C1, (unsigned char)ADDR); //
while(! I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));//
for(i=0;i<N;i++)
{
I2C_SendData(I2C1, *(DAT+i));
while(! I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));//
}
I2C_GenerateSTOP(I2C1, ENABLE);//
return 1;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
---------------------------------
F3/F4的没必要弃之不用吧。
---------------------------------
不打算折腾,来简单的,呵呵。
一周热门 更多>