在I2C调试过程中遇到问题
运行到I2C_GenerateSTART(I2C1, ENABLE); 就会出现上图波形
之后的发送数据反而没有任何信号,
void I2C1_init()
{
GPIO_InitTypeDef GPIO_InitStructure;
I2C_InitTypeDef I2C_InitStructure;
/* Configure the I2C clock source. The clock is derived from the HSI */
RCC_I2CCLKConfig(RCC_I2C1CLK_SYSCLK);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE); //Enable I2C1 Clock
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE); //Enable GPIOA Clock
//RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SRAM,ENABLE); //Enable SRAM Clock
//GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_4); //Connect PA9 to I2C1_SCL
//GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_4); //Connect PA10 to I2C1_SDA
//Config Pins
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 |GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_4); //Connect PA9 to I2C1_SCL
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_4); //Connect PA10 to I2C1_SDA
//Config I2C1
I2C_DeInit(I2C1);
I2C_Cmd(I2C1, DISABLE);
I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Disable;
I2C_InitStructure.I2C_DigitalFilter = 0x00;
I2C_InitStructure.I2C_OwnAddress1 = 0x68;
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_Timing = 0x10815E89; //Master 100khz 48Mhz A_Filter_off R_time=F_time=100ns
//I2C_InitStructure.I2C_Timing = 0x00702F3E; //Master 400khz 48Mhz A_Filter_off R_time=F_time=50ns
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_Cmd(I2C1, ENABLE);
I2C_Init(I2C1, &I2C_InitStructure);
//I2C_AcknowledgeConfig(I2C1,ENABLE);
//I2C_Cmd(I2C1, ENABLE);
}
int i2c_read(unsigned char slave_addr, unsigned char reg_addr,unsigned char length, unsigned char *data)
{
while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY) != RESET); // Test on BUSY Flag
//I2C_GenerateSTART(I2C1, ENABLE);
I2C_GenerateSTART(I2C1, ENABLE);
//while(I2C_GetFlagStatus(I2C1, I2C_FLAG_TXIS) == RESET);
I2C_SendData(I2C1,(slave_addr |
RE:STM32F030F4 TSSOP20 I2C调试问题
你改用STC的IIC高级库STM32_I2C_CPAL试试。
或者参考社区别人分享的IIC硬件调试
https://www.stmcu.org.cn/bbs/article_244_576737.html
RE:STM32F030F4 TSSOP20 I2C调试问题
回复:STM32F030F4 TSSOP20 I2C调试问题
选用高级库
选用高级库怎么讲呢?
RE:STM32F030F4 TSSOP20 I2C调试问题
RE:STM32F030F4 TSSOP20 I2C调试问题
请问你的最后怎么怎么解决的呢???
https://www.stmcu.org.cn/module/forum/thread-577721-1-1.html