Page 1 of 1

i2c pin configuration.

Posted: Mon Mar 23, 2020 4:52 pm
by rew
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.

Re: i2c pin configuration.

Posted: Mon Mar 23, 2020 6:42 pm
by Giovanni
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

Re: i2c pin configuration.

Posted: Tue Mar 24, 2020 10:50 am
by rew
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....