i2c pin configuration.

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: barthess, RoccoMarco

rew
Posts: 291
Joined: Sat Jul 19, 2014 12:59 pm
Been thanked: 6 times

i2c pin configuration.

Postby rew » Mon Mar 23, 2020 4:52 pm

Hi,
First time using I2C on STM32 / Chibios.

How am I supposed to initialize the pins for I2C use?

Code: Select all

    if (strcmp (argv[1], "init") == 0) {
      palSetPadMode (GPIOB, 6,   PAL_MODE_OUTPUT_PUSHPULL);
      for (i=0;i<100;i++)
   palTogglePad (GPIOB, 6);

      palSetPadMode (GPIOB, 6,   PAL_STM32_MODE_ALTERNATE | PAL_STM32_OTYPE_OPENDRAIN
           | PAL_STM32_ALTERNATE(1));
     
      palSetPadMode (GPIOB, 7,   PAL_STM32_MODE_ALTERNATE | PAL_STM32_OTYPE_OPENDRAIN
           | PAL_STM32_ALTERNATE(1));
     
      GPIOB -> PUPDR |= 1 << (6*2);
      GPIOB -> PUPDR |= 1 << (7*2);
      i2cStart(&I2CD1, &i2cfg1);
This seems to work, but I find it not "neat" to have to poke the pullup registers by hand.


What doesn't help is that the "demos" and "examples" often don't show how to configure pins as they have poked the configuration into the board setup file.

User avatar
Giovanni
Site Admin
Posts: 12747
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 694 times
Been thanked: 572 times
Contact:

Re: i2c pin configuration.

Postby Giovanni » Mon Mar 23, 2020 6:42 pm

You can also specify pullup by ORing the PAL constants.

Note that internal resistors are not enough, you need external resistors of low enough value.

http://wiki.chibios.org/dokuwiki/doku.p ... e_shooting

Giovanni

rew
Posts: 291
Joined: Sat Jul 19, 2014 12:59 pm
Been thanked: 6 times

Re: i2c pin configuration.

Postby rew » Tue Mar 24, 2020 10:50 am

Yes, I have external pullups, but at first I wasn't getting ANY response. So then I put the logic analyser on and as I didn't have a splitter handy, that's when I lost the external pullups.... With the pullups having too large a value, I know to expect that the low times can become longer than expected. Turns out that when I finally got things working, that didn't happen at all. Of course there was very little load on the i2c bus: only the 15cm to the logic analyser. In the real application there is only 10cm to the two I2C chips. (On my pcb there is now a 12x12mm TQFP footprint while the STM is 14x14mm, and I forgot to draw the wires between the pullups and the +3V3. And I used both VCC and +3V3 symbols for the 3.3V net. So those didn't get connected. Found two of those and then reordered the PCBs.....).

Code: Select all

For STM32F1xx they are:
[...]
For STM32F4xx they are:
So... For testing with the bad PCB I'm now using my F0 development board, but the real target is an F7....


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 3 guests