I2C implementation for STM32

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
mabl
Posts: 417
Joined: Tue Dec 21, 2010 10:19 am
Been thanked: 1 time

Re: I2C implementation for STM32

Post by mabl »

matis wrote:I'll enhance the resolution of the scope and get back to you :)


<admode>
You might want to have a look at Open Bench Logic Sniffer. It's a great product for a great price.
http://dangerousprototypes.com/docs/Ope ... ic_Sniffer
http://www.seeedstudio.com/depot/preord ... l?cPath=75
</admode>
matis
Posts: 53
Joined: Fri Jul 01, 2011 1:46 pm

Re: I2C implementation for STM32

Post by matis »

Fixed it :)

I misinterpeted the documentation of the MAX7311.

Code: Select all

void init_max7311(void)
{
#define RXBYTES 0
#define TXBYTES 3
   max7311_tx_data[0] = 0x06; /* Port 1 configuration */
   max7311_tx_data[1] = 0xFF; /* Set IO00-IO07 as input */
   max7311_tx_data[2] = 0x00; /* Set IO08-IO15 as output */
   /* transmit out 3 bytes */
   i2cAcquireBus(&I2CD1);
   i2cMasterTransmit(&I2CD1, &max7311, max7311_addr, max7311_tx_data, TXBYTES, max7311_rx_data, RXBYTES);
   while (I2CD1.id_state != I2C_READY)
   {
      chThdSleepMilliseconds(1);
   }
   i2cReleaseBus(&I2CD1);
   max7311_tx_data[0] = 0x02; /* Output port 1  */
   max7311_tx_data[1] = 0x00; /* Set IO00-IO07 low / dont care */
   max7311_tx_data[2] = 0x00; /* Set IO08-IO15 high */
   /* transmit out 3 bytes */
   i2cAcquireBus(&I2CD1);
   i2cMasterTransmit(&I2CD1, &max7311, max7311_addr, max7311_tx_data, TXBYTES, max7311_rx_data, RXBYTES);
   while (I2CD1.id_state != I2C_READY)
   {
      chThdSleepMilliseconds(1);
   }
   i2cReleaseBus(&I2CD1);
#undef RXBYTES
#undef TXBYTES
}

Did the trick. The registers needed to be written one by one, each with the address header byte. The status outputs are also inverted, therefore a 0x00 is needed on the IO08-IO15 to turn them high.
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: I2C implementation for STM32

Post by Badger »

I've been using the i2c drivers in a c++ application and I have a request: can we either have a void pointer in I2CSlaveConfig to use as a generic param passing pointer or a hook to allow adding other values into the struct?
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: I2C implementation for STM32

Post by barthess »

Hi, Badger.
Technically, adding a void pointer in struct is not a problem. Question to Giovanni, whether it correspond the ideology of the OS? Or may be OS has other mechanism for this purpose?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: I2C implementation for STM32

Post by Giovanni »

Hi,

Some driver already have hook macros to extend structures so that would not be a problem from my point of view.

Giovanni
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: I2C implementation for STM32

Post by barthess »

What driver(s) looking for examples?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: I2C implementation for STM32

Post by Giovanni »

For example in the STM32 GPT driver you can see:

Code: Select all

#if defined(GPT_DRIVER_EXT_FIELDS)
  GPT_DRIVER_EXT_FIELDS
#endif


inside the GPTDriver structure, the same approach could be used for configuration structures, something like GPT_CONFIG_EXT_FIELDS.

Giovanni
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: I2C implementation for STM32

Post by barthess »

Hook added at revision 3189.
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: I2C implementation for STM32

Post by barthess »

Hi all.
I have try to realize synchronous driver. It turned out not to much simpler or smaller. Also I have not oscilloscope nor logical analyzer to perform comprehensive tests.

I think that the current callback based driver is stable enough to merge to trunk. Is there any suggestions and comments?

Where to move from os\hal\dox\i2c.dox STM32 specific documentation?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: I2C implementation for STM32

Post by Giovanni »

I am still evaluating the synchronous option but in the meanwhile lets merge this one.

Any feedback on the current implementation before merging?

Giovanni
Post Reply