I2C using on STM32L15x

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Raig
Posts: 10
Joined: Tue Apr 26, 2011 4:00 pm

I2C using on STM32L15x

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: I2C using on STM32L15x

Post by Giovanni »

Hi,

Could you post the complete code? it is hard to tell from just the function prototype.

Giovanni
Raig
Posts: 10
Joined: Tue Apr 26, 2011 4:00 pm

Re: I2C using on STM32L15x

Post 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.zip
In 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.jpg

Raig
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: I2C using on STM32L15x

Post 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
Raig
Posts: 10
Joined: Tue Apr 26, 2011 4:00 pm

Re: I2C using on STM32L15x

Post 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.pdf

Raig
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: I2C using on STM32L15x

Post by Badger »

Try it with the address shifted down one bit, e.g 0x3B
Raig
Posts: 10
Joined: Tue Apr 26, 2011 4:00 pm

Re: I2C using on STM32L15x

Post 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
Raig
Posts: 10
Joined: Tue Apr 26, 2011 4:00 pm

Re: I2C using on STM32L15x

Post by Raig »

Hello,
I'm back like promised. Ok my 25€ Sensor is not destroyed, very good. :D
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
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: I2C using on STM32L15x

Post 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!
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: I2C using on STM32L15x

Post 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
Post Reply