我們目前正開發 STM32的應用 觸控元件為 STMPE610 PB5_I2C1_nINT0 連接 STMPE610 的INT接腳 PB6_I2C1_SCL 連接 STMPE610 的SCLK接腳 PB7_I2C1_SDA 連接 STMPE610 的 SDAT接腳 <div style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; color: rgb(34, 34, 34); font-family: Arial, Helvetica, sans-serif; font-size: 13px;">初始化後,我們嘗試透過 I2C 去讀 STMPE610的暫存器,竟然卡住: > I2C_AcknowledgeConfig(I2C1, ENABLE); while (I2C_GetFlagStatus(I2C1,I2C_FLAG_BUSY)); I2C_GenerateSTART(I2C1, ENABLE); while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); SR1 = 0x40 (I2C_FLAG_RXNE), I2C1->SR2 = 0 我們查到在stackOverflow也有人遇到類似的問題,但不知如何解: http://stackoverflow.com/questions/2556794/stm32-i2c1-start-bit-not-set-on-sr1-register 初始化的程式碼: RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOB, &GPIO_InitStructure); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //EXTI9_5_IRQn; // EXTI Line[9:5] Interrupts NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); EXTI_InitSturcture.EXTI_Line = EXTI_Line5 ; EXTI_InitSturcture.EXTI_Mode = EXTI_Mode_Interrupt ; EXTI_InitSturcture.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitSturcture.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitSturcture); // Select PB5 as EXTI Line 5 GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource5); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_Init(GPIOB, &GPIO_InitStructure); I2C_InitTypeDef I2C_InitStructure; I2C_DeInit(I2C1); I2C_SoftwareResetCmd(I2C1, ENABLE); I2C_SoftwareResetCmd(I2C1, DISABLE); I2C_Cmd(I2C1, ENABLE); I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; I2C_InitStructure.I2C_OwnAddress1 = 0x00; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit ; I2C_InitStructure.I2C_ClockSpeed = 50000; I2C_Init(I2C1, &I2C_InitStructure); I2C_ITConfig(I2C1, I2C_IT_BUF | I2C_IT_EVT, ENABLE); 請各位大大提供建議,謝謝!! |
RE:I2C1 卡死在 RXNE 旗標(0x40)