请教原子哥,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;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
write_CFGbyte(0x00,0x20);//????8563
write_CFGbyte(0x02,c8563_Store[0]);
write_CFGbyte(0x03,c8563_Store[1]);//这里写操作会出错
write_CFGbyte(0x04,c8563_Store[2]);
void write_CFGbyte(unsigned char CFG_add,unsigned char CFG_data)
{
IIC_Start();
IIC_Send_Byte(write_ADD);
IIC_Wait_Ack();
if(F0 == 1)
{
SystemError = 1;
return;
}
IIC_Send_Byte(CFG_add);
IIC_Wait_Ack();
if(F0 == 1)
{
SystemError = 1;
return;
}
IIC_Send_Byte(CFG_data);
IIC_Wait_Ack();
if(F0 == 1)
{
SystemError = 1;
return;
}
IIC_Stop();
}
---------------------------------
这我也不太清楚,你慢慢找找问题吧。
一周热门 更多>