STM32F103 I2C change mapping on fly

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

Moderator: RoccoMarco

Post Reply
Tuxford
Posts: 26
Joined: Fri Nov 06, 2020 3:28 pm
Has thanked: 4 times
Been thanked: 4 times

STM32F103 I2C change mapping on fly

Post by Tuxford »

There is a case when two pairs PB6/PB7 and PB8/PB9 are used with different I2C slaves on I2C1. Is it possible change only AFIO->MAPR without i2cStart/i2cStop or restart it required?

Chibios 20.3
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F103 I2C change mapping on fly

Post by Giovanni »

Hi,

It is not safe in my opinion, you could have glitches pm SDA/SCL depending on how GPIO is designed. Make sure to not do that while I2C is active anyway.

Giovanni
Tuxford
Posts: 26
Joined: Fri Nov 06, 2020 3:28 pm
Has thanked: 4 times
Been thanked: 4 times

Re: STM32F103 I2C change mapping on fly

Post by Tuxford »

Giovanni wrote:Hi,

It is not safe in my opinion, you could have glitches pm SDA/SCL depending on how GPIO is designed. Make sure to not do that while I2C is active anyway.

Giovanni

Read/Write operations are protected. So so switching mode is not performed during activity. It is just question of software.
rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 14 times

Re: STM32F103 I2C change mapping on fly

Post by rew »

I would think that the IO pad design on the chip is synchronous. So if you change from AFx to GPIO on the fly, at one point the I2C module is providing the data driving the pin and the next clock it will revert back to the ODR. This is just like changing another pin in the same ODR: Glitches would be bad.

I think it is safe and can be done. Won't hurt to check for yourself though. The critical moment is when you switch from GPIO to I2C and back. So you can just do that switch a million times a second without sending any I2C data, so you can see if the scope triggers on anything, and test it a 100 million times in under two minutes....
Post Reply