Page 2 of 2
Re: I2C using on STM32L15x
Posted: Tue Feb 14, 2012 1:46 pm
by Raig
What can I do for work around?
Raig
Re: I2C using on STM32L15x
Posted: Tue Feb 14, 2012 2:12 pm
by mabl
Without ever having used the I2C module - couldn't you just use:
palSetPadMode(GPIOB, 10, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN);
Re: I2C using on STM32L15x
Posted: Tue Feb 14, 2012 2:15 pm
by Giovanni
Right, try declaring both clock and data as opendrain, do you have external pull-up resistors right?
Giovanni
Re: I2C using on STM32L15x
Posted: Thu Feb 16, 2012 12:17 am
by Raig
Hello again,
the initialization of the I2C pins works fine with the OR operation posted by mabl. My sensor delivers stable values now, in moment I got 1004.8hPa here in Berlin.
Raig
Re: I2C using on STM32L15x
Posted: Tue Nov 26, 2013 1:44 am
by genosensor
I'm also having trouble getting I2C to function on an STM32L-discovery board.
The working example user Raig had posted in February is no longer available at:
http://rapose.de/Raig/ChibiOS_2.4.0_I2C ... m_Raig.zipDoes anyone else have a copy of that zip file?
Has anyone managed to get I2C working on the STM32L?
If so, could you please provide an working example?
For me, the I2C unit refuses to drive the bus because it reports the bus as BUSY (bit set in SR2)
Most likely, this means that the functional unit is not attached to the I2C pads properly.
Here's how I'm doing that:
Code: Select all
palSetGroupMode(GPIOB, 3, 8, PAL_MODE_ALTERNATE(4) |
PAL_MODE_OUTPUT_OPENDRAIN | PAL_STM32_OSPEED_MID1);
I have verified that PB8 and PB9 can drive the I2C bus when configured as open drain outputs.
(I can bang the bits)
Other masters on the bus are not affected, so I know neither SDA or SCL are being pulled low.
I'm not absolutely sure about PAL_MODE_ALTERNATE(4), but that's what the reference manual
and examples for other STM32 variants seem to imply.
I'm working with ChiBiOS 2.6.1
Thanks in Advance for any help!
Re: I2C using on STM32L15x
Posted: Tue Nov 26, 2013 9:03 am
by Giovanni
Do you have external pull up resistors? the alternate modes are listed in the Datasheet not in the Reference Manual. You also could give a look to the guide Barthess wrote in the community section of the wiki.
Giovanni
Re: I2C using on STM32L15x
Posted: Tue Nov 26, 2013 9:25 am
by genosensor
I can bang the bits when they are configured as open drain but not mapped to alternative_fuction(4).
The other I2C masters on the same bus can access slaves. That proves that the bus and associated pull ups are working.
You are right about the datasheet vs. the reference. My mistake. Nonetheless, it looks like AFIO4 is the correct selection.
Yes, I have looked at the wiki. But, the pad set up for the STM32L is different.
I've attached the little test program in the hopes that another set of eyes will catch my stupid mistake.
Re: I2C using on STM32L15x
Posted: Tue Nov 26, 2013 9:50 am
by Giovanni
I don't see obvious errors, try increasing the pad speed to mid2 or high.
Giovanni
Re: I2C using on STM32L15x
Posted: Thu Nov 28, 2013 8:02 am
by genosensor
[SOLVED]
It was a pin configuration issue after all.
This is a proper initialization for the STM32L1xx:
Code: Select all
/* I2C1 */
static const I2CConfig i2cfg1 = {
OPMODE_I2C,
100000,
STD_DUTY_CYCLE
};
int main(void) {
halInit();
chSysInit();
/* I2C1 SCL on PB8, SDA on PB9 */
palSetGroupMode(GPIOB,3,8, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN);
i2cStart(&I2CD1, &i2cfg1);
It seems that we all got confused by the need to declare the alternate function pin as OPENDRAIN.
These alternate function pads are *NOT* a type of output pad!!
As a result, this was causing palSetGroupMode to quietly generate an invalid moder mask:
Code: Select all
palSetGroupMode(GPIOB,3,8, PAL_MODE_ALTERNATE(4) | PAL_OUTPUT_OPENDRAIN);
This sort of thing is so insidious that it got me thinking about a way to flag the error at compile time.
What's needed is a check to ensure that the result of combining attributes with the logical OR operator
equals that of combining them with XOR. I just can't think of how to coax the 'C' preprocessor to do this.
Any Ideas?