I2C channel 2 does not wiggle the pin

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

Moderators: RoccoMarco, barthess

kb1gtt
Posts: 41
Joined: Sat Jul 09, 2016 11:29 am
Has thanked: 11 times
Been thanked: 2 times

I2C channel 2 does not wiggle the pin

Postby kb1gtt » Tue Jan 19, 2021 11:38 pm

Hello and thanks for the great work.

I'm having trouble with getting I2CD2 to function. This was working yesterday, and it is not working today. I have backed up to the code that was working yesterday, and that code no longer works today. Currently when i2cMasterTransmitTimeout is called, the pins hold steady at the top rail per the pullup resistor, and the STM32 never pulls it low. It appears that the I2C is never connected to the physical pin.

I have a program where I2CD1 has been working, and I2CD2 has been intermittent. The general flow of main.c is like this.

Code: Select all

i2cStart(&I2CD2, &i2cconfig);
i2cAcquireBus(&I2CD2);     

// send it
int ret = i2cMasterTransmitTimeout(&I2CD2, I2C_SLAVE_ADDRESS, &cmd, 1, i2c_buf, len, 1000);  // timeout 1000
i2cErrors = i2cGetErrors(&I2CD2);

if (ret != MSG_OK) {
  for (i = 0; i < len; i++) {
    i2c_buf[i] = 0;     // Clear the buffer if no new data
  }

i2cReleaseBus(&I2CD2);
i2cStop(&I2CD2);


In the above "ret" returns with -1 which I believe means it timed out. However "i2cErrors" returns with a 0. Per the below link, I was expecting at least the 0x20 timeout flag. However I get no flags from i2cGetErrors
https://www.playembedded.org/blog/stm32-i2c-chibios/

I think I have the DMA's setup properly. Even if I did not, then I should still be OK as expect I only preform one task at a time. There is some chance the USB terminal could be a conflict with the DMA resources. I'm not sure how to verify the USB ports DMA resources. Here's a snippet of mcuconf.h which details the I2C DMA. I do not expect to be using USART4, SPI3 or I2C3, those are detailed as FALSE. So I expect those are not being used by the USB debug serial port.

Code: Select all

/*
 * I2C driver system settings.
 */
#define STM32_I2C_USE_I2C1                  TRUE
#define STM32_I2C_USE_I2C2                  TRUE
#define STM32_I2C_USE_I2C3                  FALSE
#define STM32_I2C_BUSY_TIMEOUT              50
#define STM32_I2C_I2C1_RX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 0)
#define STM32_I2C_I2C1_TX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 6)
#define STM32_I2C_I2C2_RX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 2)
#define STM32_I2C_I2C2_TX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 7)
#define STM32_I2C_I2C3_RX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 2)
#define STM32_I2C_I2C3_TX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 4)
#define STM32_I2C_I2C1_IRQ_PRIORITY         5
#define STM32_I2C_I2C2_IRQ_PRIORITY         5
#define STM32_I2C_I2C3_IRQ_PRIORITY         5
#define STM32_I2C_I2C1_DMA_PRIORITY         3
#define STM32_I2C_I2C2_DMA_PRIORITY         3
#define STM32_I2C_I2C3_DMA_PRIORITY         3
#define STM32_I2C_DMA_ERROR_HOOK(i2cp)      osalSysHalt("DMA failure")


This works for I2C1, so I expect I am properly handling the 2 bytes requirement. The IO is setup with these lines. I communicate as expected on PB6 and PB7, however PF0 and PF1 stopped working and the pull up resistor indicates that I'm connected properly to those IO pins.

Code: Select all

  // PMBUS/i2C - use this on the Arduino connector
  // PB6/I2C1_SCL --> D1          PF1/I2C2_SCL
  // PB7/I2C1_SDA --> D0          PF0/I2C2_SDA
  palSetPadMode(
      GPIOB,
      6,
      PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_PULLUP); // SCL this is needed because board.h does not seem to work properly. TODO put this in board.h
  palSetPadMode(
      GPIOB,
      7,
      PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_PULLUP); // SDA this is needed because board.h does not seem to work properly. TODO put this in board.h
  palSetPadMode(
      GPIOF,
      1,
      PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_PULLUP); // SCL this is needed because board.h does not seem to work properly. TODO put this in board.h
  palSetPadMode(
      GPIOF,
      0,
      PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_PULLUP); // SDA this is needed because board.h does not seem to work properly. TODO put this in board.h


this is with an Olimex STM32-E407 board. Attached is a copy of main.c, and my config files. If I have not provided enough information, then additional details could be obtained from those files. This is ChibiOS 20.3 and I'm using ChibiStudio on Win10. As well I have found I need to launch the GCC 7.0 launcher. If I do not then I appear to get compiler issues that cause kernel panic and unhandled exceptions.

Are there any suggestions about what could be going wrong? Am I not properly configuring the pin?
Attachments
Project_draft.zip
(41.71 KiB) Downloaded 139 times

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

Re: I2C channel 2 does not wiggle the pin

Postby Giovanni » Wed Jan 20, 2021 8:59 am

Are you able to toggle that pin as GPIO? it could be an HW issue.

Giovanni

steved
Posts: 823
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

Re: I2C channel 2 does not wiggle the pin

Postby steved » Wed Jan 20, 2021 9:56 am

Could the same I2C functions be assigned to two pins at once? (Easy to miss if you start from an existing board configuration file).

Not sure what determines which pins actually perform the configured function in that situation; could be random, or first/last one wins, or....

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

Re: I2C channel 2 does not wiggle the pin

Postby Giovanni » Wed Jan 20, 2021 10:17 am

Definitely not, an alternate function MUST be assigned to a single pin so do it in board.h or at runtime, not both.

Giovanni

steved
Posts: 823
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

Re: I2C channel 2 does not wiggle the pin

Postby steved » Wed Jan 20, 2021 2:03 pm

Giovanni wrote:Definitely not, an alternate function MUST be assigned to a single pin so do it in board.h or at runtime, not both.

Giovanni

That's exactly the point I was trying to make, but from the opposite direction.
Been caught that way recently - starting from a board configuration file intended for a larger package device, so of course only defined the pins I was using on my small package - turned out some of the functionality I wanted was already defined on the "extra" pins.

kb1gtt
Posts: 41
Joined: Sat Jul 09, 2016 11:29 am
Has thanked: 11 times
Been thanked: 2 times

Re: I2C channel 2 does not wiggle the pin

Postby kb1gtt » Wed Jan 20, 2021 4:05 pm

If board.h and the runtime detail the same thing, is that OK? I understand the concern about 2 different conflicting declarations of the pin's function. However if they are both declaring the same thing, is that OK? I found I could get it to work with the runtime. However I failed to get it to work with board.h. It appears I just figured out why my previous attempt with board.h failed. See below snippets.

board.h snippet was this

Code: Select all

#define GPIOB_I2C1_SCL              6U
#define GPIOB_I2C1_SDA              7U
...
#define GPIOF_I2C2_SDA              0U
#define GPIOF_I2C2_SCL              1U
...
#define VAL_GPIOB_AFRL
...
                                     PIN_AFIO_AF(GPIOB_PIN5, 0U) |          \
                                     PIN_AFIO_AF(GPIOB_PIN8, 0U) |          \
                                     PIN_AFIO_AF(GPIOB_PIN9, 0U))
#define VAL_GPIOB_AFRH              (PIN_AFIO_AF(GPIOB_I2C1_SCL, 4U) |      \
                                     PIN_AFIO_AF(GPIOB_I2C1_SDA, 4U) |      \
                                     PIN_AFIO_AF(GPIOB_PIN10, 5U) |      \

...


I just changed to the below, notice I2C has moved from AFRH to AFRL.

Code: Select all

#define VAL_GPIOB_AFRL       
...
                                     PIN_AFIO_AF(GPIOB_PIN5, 0U) |          \
                                     PIN_AFIO_AF(GPIOB_I2C1_SCL, 4U) |   \
                                     PIN_AFIO_AF(GPIOB_I2C1_SDA, 4U))
#define VAL_GPIOB_AFRH (PIN_AFIO_AF(GPIOB_PIN8, 0U) |       \
                                     PIN_AFIO_AF(GPIOB_PIN9, 0U) |          \
                                     PIN_AFIO_AF(GPIOF_PIN10, 0U) |         \
...


It appears I2C1 was working because my runtime settings were properly setting the alt mode, while board.h was wrong. It is now working with just the board.h declaration. As well I have added I2C2 to the board.h and that is now working and I have removed those declarations from the runtime.

I do not know why I2C2 was not working yesterday, and this morning it is now working. I did a make clean this morning, so perhaps that fixed something in the compile chain. I have not touched board.h or any similar config files for weeks, so I do not expect the compile chain to have gone wrong.

It now working, so I guess until it breaks again, thanks for the input and feedback. I believe I am all set now.


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 17 guests