2009-12-18 01:58 AM
I2C I2C_GenerateSTART
2011-05-17 04:31 AM
Help
I use the I2C2 with pin PB10 and PB11, but when I use the command I2C_GenerateSTART(ENABLE) only the pin PB10 goes low and so I can't generate the Start Condiction. Can you help me?2011-05-17 04:31 AM
We are using I2C2 without a problem with the start bits. Check your GPIO setup. May be a hardware problem, maybe PB11 is being pulled up.
2011-05-17 04:31 AM
I'am sure that the hardware is correct, because if I configure the pins in Open Drain, I can move them. I use the STM32F101RBT6
Do you use a STM32101 or other?2011-05-17 04:31 AM
SPI2 using PB10/11 on a 103: no problem.
However a low state could appear on some I2C pin at the time the I2C module clock is enabled, which may irritate connected slaves. It might be better to start the I2C clock before the pins are enabled for I2C. [ This message was edited by: prx on 16-12-2009 14:54 ]2011-05-17 04:31 AM
Hi federico,
Just to discard the hardware problem,have you tried the I2C examples from STM32 software library? I geuss I2C2 is used as master in one of them. Cheers.2011-05-17 04:31 AM
Hi,
I'm using both I2C1 and I2C2 + DMA with STM32F101RBT6 without a problem, but development has been horrible, lots of problems and ST examples are far from good...2011-05-17 04:31 AM
All necessary configuration:
pin definition: /* Configure I2C2 pins: SCL and SDA */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_Init(GPIOB, &GPIO_InitStructure); clock definition: RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3 | RCC_APB1Periph_TIM4 | RCC_APB1Periph_I2C1 | RCC_APB1Periph_I2C2, ENABLE); interrupts: I2C2EVConfig(FunctionalState NewState) { NVIC_InitTypeDef NVIC_InitStructure; /* Configures the I2C2EV global Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = I2C2_EV_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 8; if (NewState==ENABLE) { /* I2C2EV IT Channel enable */ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); I2C_ITConfig(I2C2, I2C_IT_EVT | I2C_IT_BUF, ENABLE); } else { /* I2C2EV IT Channel disable */ NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE; NVIC_Init(&NVIC_InitStructure); I2C_ITConfig(I2C2, I2C_IT_EVT | I2C_IT_BUF, DISABLE); } } I2C2ERConfig(FunctionalState NewState) { NVIC_InitTypeDef NVIC_InitStructure; /* Configures the I2C2ER global Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = I2C2_ER_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 10; if (NewState==ENABLE) { /* I2C2ER IT Channel enable */ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); I2C_ITConfig(I2C2, I2C_IT_ERR, ENABLE); } else { /* I2C2ER IT Channel disable */ NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE; NVIC_Init(&NVIC_InitStructure); I2C_ITConfig(I2C2, I2C_IT_ERR, DISABLE); } } and then regarding I2c functions themselves: #define ClockSpeed 100000 void I2C_Init() { I2C_InitTypeDef I2C2_InitStructure; KERN_INT_I2C2EVConfig(DISABLE); KERN_INT_I2C2ERConfig(DISABLE); /* Resets I2C2 */ I2C_DeInit(I2C2); I2C_Cmd(I2C2, DISABLE); I2C_SoftwareResetCmd(I2C2, ENABLE); I2C_SoftwareResetCmd(I2C2, DISABLE); I2C_DeInit(I2C2); /* I2C2 configuration */ I2C2_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C2_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; I2C2_InitStructure.I2C_OwnAddress1 = I2C2_SLAVE_ADDRESS7; I2C2_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C2_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C2_InitStructure.I2C_ClockSpeed = ClockSpeed; I2C_Init(I2C2, &I2C2_InitStructure); /* Enables I2C2 */ I2C_Cmd(I2C2, ENABLE); /* Enable CRC clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE); /* Enables I2C2 event and buffer interrupt */ I2C2EVConfig(ENABLE); /* Enables I2C2 error interrupt */ I2C2ERConfig(ENABLE); } And then reading from the bus: I2C2_Master_BufferWrite(uint8_t* pBuffer, uint8_t NumByteToWrite){ I2C_GenerateSTOP(I2C2, ENABLE); I2C_Init(); /* Bunch of DMA configuration */ I2C_ITConfig(I2C2, I2C_IT_EVT | I2C_IT_ERR, ENABLE); /* Bunch of DMA configuration */ /* Generate the START */ I2C_GenerateSTART(I2C2, ENABLE); } This should then launch the ISR if configured correctly. regards, ;)2011-05-17 04:31 AM
Hi jvaque
Can you show me the configuration of I2c_2? Thank you?