Page 1 of 2
I2C using on STM32L15x
Posted: Fri Feb 10, 2012 9:22 pm
by Raig
I like to use the I2C2 interface on my STM32L Discovery for an pressure sensor (MS5803). I take the function "status = i2cMasterTransmitTimeout(&I2CDx, ms5803_addr, ms5803_tx_data, 2, ms5803_rx_data, 2, tmo);" and the initialisation like de-scripted in the testhal examples (2.4.0).
All what comes out of my I2C is the address byte, but no tx_data which contain the commands for the sensor. What do I wrong?
Re: I2C using on STM32L15x
Posted: Fri Feb 10, 2012 9:32 pm
by Giovanni
Hi,
Could you post the complete code? it is hard to tell from just the function prototype.
Giovanni
Re: I2C using on STM32L15x
Posted: Sat Feb 11, 2012 12:42 pm
by Raig
Hy Giovanni,
I prepared a project which shows the problem. You can download it here:
http://rapose.de/Raig/ChibiOS_2.4.0_I2C_Problem_Raig.zipIn the demo folder you will find my RV project. It should easily compile. On the I2C2 port (PB10, PB11) of the stm32L discovery the problem comes out.
Additional picture of my locig analyzer
http://www.rapose.de/Raig/I2C%20locig%20analyser%20Raig.jpgRaig
Re: I2C using on STM32L15x
Posted: Sat Feb 11, 2012 1:02 pm
by Giovanni
Looking at the diagram it seems the slave does not acknowledge the address, is the address correct?
Anyway, I hope barthess can read it better, he is the I2C expert

Giovanni
Re: I2C using on STM32L15x
Posted: Sat Feb 11, 2012 1:55 pm
by Raig
Yes, the address is 1110111 or 1110110 depends on a pin. In hexa is this 0x77 or 0x76. This is what come out. The response of the sensor is equal to both addresses. For information the data sheet of the sensor.
http://www.rapose.de/Raig/MS5803-02BA%20005.pdfRaig
Re: I2C using on STM32L15x
Posted: Sat Feb 11, 2012 2:30 pm
by Badger
Try it with the address shifted down one bit, e.g 0x3B
Re: I2C using on STM32L15x
Posted: Sat Feb 11, 2012 5:33 pm
by Raig
Thank's Badger,
for the hint. To be sure not to have the wrong address I wrapped a loop around the I2C output function. With the debugger I tried the 128 possibilities, every time the same result.
May I destroyed the sensor

. I got more but in the office but this is in the opposite site of the town. Monday I try another exemplar. I let you know the result and in the meanwhile thank's to all supporters.
Raig
Re: I2C using on STM32L15x
Posted: Tue Feb 14, 2012 12:33 am
by Raig
Hello,
I'm back like promised. Ok my 25€ Sensor is not destroyed, very good.
The reason why the sensor don't give an acknowledge was a wrong initialisation of the I2C ports. To use the pins of I2CD2 I initialized the pins with alternate mode (4) for I2C function. But the open drain bit of this pins (OTYPER 10+11) wasn't set. This led to a conflict on the I2C bus.
Problem recognized but not solved because:
palSetPadMode(GPIOB, 10, PAL_MODE_OUTPUT_OPENDRAIN);
palSetPadMode(GPIOB, 11, PAL_MODE_OUTPUT_OPENDRAIN);
palSetPadMode(GPIOB, 10, PAL_MODE_ALTERNATE(4));
palSetPadMode(GPIOB, 11, PAL_MODE_ALTERNATE(4));
this sequence set first the necessary open drain bits but the second initialization of the also necessary alternate mode 4 resets the open drain bits. If you change the sequence to initialize the alternate function first and then the open drain mode the same problem. The alternate function is now reset. To see that is really work I set the necessary bits of the open drain and alternate function mode by debugger. Then I get a answer of my sensor.
I think it would be nice to initialize the open drain bits together with the I2C alternate function because this glue together.
In between I would thank you for a work around!
Raig
Re: I2C using on STM32L15x
Posted: Tue Feb 14, 2012 12:44 am
by Badger
Raig wrote:I think it would be nice to initialize the open drain bits together with the I2C alternate function because this glue together.
The problem with this is that there are several sets of pins that each i2c device might be mapped to. This is definitely something that could be included in the docs though!
Re: I2C using on STM32L15x
Posted: Tue Feb 14, 2012 9:29 am
by Giovanni
Ideally the STM32 reference manual and datasheet would have to be included in documentation

The OS offers a lot of abstraction and we strive to make it more convenient to use but embedded programming is still hard, details cannot be overlooked.
Giovanni