cancel
Showing results for 
Search instead for 
Did you mean: 

I2C_Timing_Config_Tool for F0 and F3

conor
Associate II
Posted on February 26, 2013 at 02:34

I need to configure an I2C slave on an STM32F0 .

The peripheral library refers to an 'I2C_Timing_Config_Tool' and googling suggests that application note AN4235

 I2C timing configuration tool for STM32F3xxxx and STM32F0xxxx

 is relevant. All traces of this document appear to have been removed from st.com.

Since this incarnation of I2C is new to the F0 and F3 (as far as I know), I could use a little guidance.

-- Conor

#amazing-google-skills #i2c-timing_config_tool-stm32f0
10 REPLIES 10
Posted on February 26, 2013 at 03:11

Not sure they help much, as I recall the primary issue is how one gets to the 400 KHz rate, if that is absolutely critical. The way the dividers work on the STM32 parts there were some games played with the duty cycle depending on your core/bus clock settings.

If a rate under 400 KHz is fine for your application I wouldn't lose a lot of sleep over it.

A lot of content from the website seems to have been lost, and other files/paths renamed in an effort to have a more unified naming convention. This may be resolved over time. I couldn't find the I2C stuff you mention on this box, but will check some other machines when I get some time.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
conor
Associate II
Posted on February 26, 2013 at 03:24

I'm sure it would be appreciated by more than just me if you turn something up.

I don't need speed. I use an F4 when I need 400kHz (without clock stretching). For a 100kHz slave, I'm probably safe enough picking a sample sEE_I2C_TIMING value from the library, I guess.

Thanks for the reassurance, Clive.
Posted on February 26, 2013 at 03:44

https://docs.google.com/file/d/1aPtLzPBMHpVwJBBAd6fDXAmv5eje1B4mx3wqvUtYP-lRrKOjrd1jYFc5RnX8/edit?usp=sharing

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
conor
Associate II
Posted on February 26, 2013 at 20:33

Thanks again, Clive. Interesting creation date on that doc 🙂

I just noticed that I forgot to R the FM. There are tables of example timing settings that answer all my questions.

Now, if only we could get the excellent doc writers to take over the management of the st.com site....

-- Conor

rcholewa
Associate II
Posted on April 15, 2013 at 17:32

hi,

is there any news on setting I2C_Timing for 400khz speed on STM32F3 ?

regards,

cholo
Posted on April 15, 2013 at 18:12

Suggest you review the I2C_TIMINGR register configuration examples in RM0316, seems like some pretty basic math involved based on your I2CCLK. Absent an Excel sheet a calculator, pencil and paper would suffice.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
rcholewa
Associate II
Posted on April 20, 2013 at 00:46

Thanks for the clue.

I've done my lesson and calculated proper? values for the I2Cx_TIMINGR register basing on the examples from RM0316.

I'm trying to setup STM32F3 (discovery board) as slave in the interrupt mode (400KHz bus, hardware pullups) but interrupt is never called.

Could you please take a look at the excerpt from code.

static void I2C_Config(void)

{

    //I2C_DeInit(I2C1);        //Deinit and reset the I2C to avoid it locking up

    //I2C_SoftwareResetCmd(I2C1);

  /* Enable UART clock */

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);

    /* Enable GPIO clock */

    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); // enabled in TIM_Config also

  /* Reset I2Cx IP */

  //RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE);

  /* Release reset signal of I2Cx IP */

  //RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, DISABLE);    

    

  GPIO_InitTypeDef GPIO_InitStructure;

    

    /* PB6 - SCL; PB7 - SDA */

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_4);

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_4);

  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOB, &GPIO_InitStructure);

  I2C_InitTypeDef I2C_InitStructure;

  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;

  I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable;

  I2C_InitStructure.I2C_DigitalFilter = 0x00;

  I2C_InitStructure.I2C_OwnAddress1 = I2C1_SLAVE_ADDRESS;

  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;

  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;

  I2C_InitStructure.I2C_Timing = 0x50330309; // 400KHz | 8MHz-0x00310309; 16MHz-0x10320309; 48MHz-50330309

    I2C_Init(I2C1, &I2C_InitStructure);

    

  NVIC_InitTypeDef NVIC_InitStructure;

  /* Configure the SPI interrupt priority */

  NVIC_InitStructure.NVIC_IRQChannel = I2C1_EV_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

  /* Enable I2C */

  I2C_Cmd(I2C1, ENABLE);

  /* Enable Interrupts */

    I2C_ITConfig(I2C1, I2C_IT_ADDRI | I2C_IT_RXI, ENABLE);    

}

void I2C1_EV_IRQHandler(void)

{

  ...

}

Regards,

cholo
rcholewa
Associate II
Posted on April 20, 2013 at 12:43

if I change slave address to 0x0 (and send to that address from master) it works but I don't understand why ???

conor
Associate II
Posted on April 23, 2013 at 20:02

That's a feature called General Call.

You can read about it here. This will also explain why you have the address wrong. 

http://www.totalphase.com/support/kb/10039/