STM32F3DISCOVERY : using the I2C protocol

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

Moderator: RoccoMarco

giazax
Posts: 12
Joined: Tue Nov 26, 2013 4:43 pm

STM32F3DISCOVERY : using the I2C protocol

Post by giazax »

Hi all,
i'm using the eval board STM32F3-DISCOVERY to interface a Humidity sensor (SI7020) with the i2c protocol (ICD1 BUS).
After many attempts...i see nothing, the status variable (after the i2cMasterTransmitTimeout command) is -2(?) and i'don't know why

..so my questions are :

The required PAL settings for the board (STM32F3-DISCOVERY) are : (i used the configuration in : http://www.chibios.org/dokuwiki/doku.php?id=chibios:community:guides:i2c_trouble_shooting....

Code: Select all

palSetPadMode(GPIOA, GPIOA_PIN9 , PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN) ;
  palSetPadMode(GPIOA, GPIOA_PIN10, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN) ;


where
PA9 is the SCL
PA10 is the SDA

2- the i2cconfig parameters are (i have no refereces about them...so i used the same configuration for the LSM303DLCH sensor) :

Code: Select all

static const I2CConfig i2cconfig = {
  STM32_TIMINGR_PRESC(8U)  | STM32_TIMINGR_SCLDEL(3U) | STM32_TIMINGR_SDADEL(3U) |
  STM32_TIMINGR_SCLH(3U)   | STM32_TIMINGR_SCLL(9U),
  0,
  0
};



i didn't find any referece about it....are these correct or not?

3 - my command sequence is :

Code: Select all

uint8_t rxbuf[6];
 uint8_t txbuf[6];
 SensorAddress = 0x40; //is correct

 txbuf[0] = myCommand; //is correct

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

  status = i2cMasterTransmitTimeout(&I2CD1, SensorAddress, txbuf, 1, rxbuf,0, TIME_INFINITE);
  chprintf(chp, "status =  %d \n" , status );
  i2cStop(&I2CD1);
  i2cReleaseBus (&I2CD1);



the status is always -1....and i have strange results with other commands.....

what's wrong with it?

any suggestions would be appreciated

thanks in advance

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

Re: STM32F3DISCOVERY : using the I2C protocol

Post by Giovanni »

Hi,

That code does not tell me much. Do you have external pullup resistors? are wires short? are you looking at the bus with an analyser?
You may also try a lower speed, the settings are described in details in the Reference Manual.

Giovanni
giazax
Posts: 12
Joined: Tue Nov 26, 2013 4:43 pm

Re: STM32F3DISCOVERY : using the I2C protocol

Post by giazax »

Hi Giovanni,
i have not a logic analyser, the hardware is ok (...external pullup resistors and ... wires short)

i'lltry a lower speed

thanks

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

Re: STM32F3DISCOVERY : using the I2C protocol

Post by Giovanni »

You may consider something cheap like this one: http://www.robot-italy.com/it/zeroplus- ... lyzer.html

It is what I use at home.

Giovanni
giazax
Posts: 12
Joined: Tue Nov 26, 2013 4:43 pm

Re: STM32F3DISCOVERY : using the I2C protocol

Post by giazax »

hi,
in attachment the display from the logic analyser....i see nothing.
(the settings are correct, I tested the analyser with the lsm303dlhc sensor on board)


giancarlo


p.s
my configuration for the I2C2 I/O setup is :
palSetPadMode(GPIOA, GPIOA_PIN9 , PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN) ; //SCL
palSetPadMode(GPIOA, GPIOA_PIN10, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN) ; //SDA
Attachments
i2c2.jpg
i2c2.jpg (286.51 KiB) Viewed 5989 times
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F3DISCOVERY : using the I2C protocol

Post by Giovanni »

Do you get a trigger? start the sampling just before the transmit operation (put a breakpoint there).
Also, try enlarging the samples buffer, it is set to 2k now, put it at 64k, may be we are not seeing anything because this.

Giovanni
giazax
Posts: 12
Joined: Tue Nov 26, 2013 4:43 pm

Re: STM32F3DISCOVERY : using the I2C protocol

Post by giazax »

hi giovanni,
the trigger is in default...i tried with 64 k...but nothing again....


thanks
giancarlo
giazax
Posts: 12
Joined: Tue Nov 26, 2013 4:43 pm

Re: STM32F3DISCOVERY : using the I2C protocol

Post by giazax »

hi giovanni,
in attach the display for the lsm sensor on board....it seems ok

is there any pins setup and/or other parameters i missed?

thanks for any suggestion

giancarlo
Attachments
lsmsensor.jpg
lsmsensor.jpg (229.61 KiB) Viewed 5981 times
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F3DISCOVERY : using the I2C protocol

Post by Giovanni »

Put the buffer at 64K an try to read the whole sequence, then verify if all bytes are ACKed.

Giovanni
giazax
Posts: 12
Joined: Tue Nov 26, 2013 4:43 pm

Re: STM32F3DISCOVERY : using the I2C protocol

Post by giazax »

ok,
i'll try.....the max buffer is 32k

giancarlo
Post Reply