2013-11-22 08:10 AM
Hi,
here my code for I2C setup on STM32F051R8 (STM32 discovery board practically)void set_I2C(void){
GPIO_InitTypeDef GPIO_InitStructure; I2C_InitTypeDef I2C_InitStructure;RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);/* Configure the I2C clock source. The clock is derived from the HSI */
RCC_I2CCLKConfig(RCC_I2C1CLK_SYSCLK);GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_1);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_1);//Configure pins: SCL and SDA ------------------
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_Init(GPIOB, &GPIO_InitStructure);I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
I2C_InitStructure.I2C_DigitalFilter = 0x00; I2C_InitStructure.I2C_OwnAddress1 = 0x00; // MPU6050 7-bit adress = 0x68, 8-bit adress = 0xD0; I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; //I2C_InitStructure.I2C_Timing = 0xA0120227; I2C_InitStructure.I2C_Timing = 0x20310A0D; I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;I2C_Init(I2C1, &I2C_InitStructure);
I2C_Cmd(I2C1, ENABLE);
}
but when in the main I try to send one data: I2C_SendData(I2C1, 0xAA); I don't see any signal on the Pb6 PB7. Please, can you tell me what's wrong? Thanks a lot in advance. #stm32 #i2c #stm32f02013-11-22 10:21 AM
Please, can you tell me what's wrong?
Do you have any external pull-ups? Otherwise you're not going to see any pin transitions.2013-11-23 06:49 AM
Hi Clive,
I've tried with and withoud external pullups (22.7 k)and I tried with thisGPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
and thisGPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_PU;
Can you help me to understand what's the problem?Thanks a lot in advance,Peppe.2013-11-23 07:14 AM
Isn't the bus protocol a little more complex than just using SendData
This uses the same PB6/7 pins STM32F0xx_StdPeriph_Lib_V1.1.0\Utilities\STM32_EVAL\STM320518_EVAL\stm320518_eval_i2c_tsensor.c and there are other examples within the library.2013-11-23 08:24 AM
Hi Clive,
well, I've just used SendData because I wanna know if the I2C is correctly set up before writing more code.... but the problem is that I do not see any data on the bus...2013-11-24 01:36 AM
So Clive,
do you have any idea about the error I make in the set up?If I use the send command I should see some data in the SDA at scope, correct?Let me know and thanks in advance,Peppe.2013-11-24 05:14 AM
The initialization code looks reasonable enough, not sure on the timing parameter. This is not a part I'm actively using, and a protocol/implementation I'm not a big fan of.
I've cited an example I think I'd start with as a reference point. I don't think that a SendData absent any surrounding control and sequencing is going to do the job here. I think you are going to need to pay more attention to the status and control of the peripheral, and perhaps that will indicate why it's not placing the data you expect on the wire.2013-11-24 09:58 AM
Hi Clive,
I understand well what you mean but the problem is that I don't see neither the clock on SCL line... well I am fear that I miss something in I2C parameter setting...I'd like a lot an help.Thanks,Peppe.2013-11-24 02:55 PM
I'd like a lot of help
I'm not looking to do dev work on the STM32F0. Did you have an hourly rate in mind?2013-11-25 02:08 PM
Ahahah...
I am sorry Clive but it was a type error mistake :)I wanted to tell you: ''I'd like an help in order to get a base I2C set up''.Thanks in any case for your time :)Ciao,Peppe.