Page 12 of 35

Re: I2C implementation for STM32

Posted: Fri Jul 29, 2011 9:07 am
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>

Re: I2C implementation for STM32

Posted: Fri Jul 29, 2011 10:17 am
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.

Re: I2C implementation for STM32

Posted: Mon Aug 01, 2011 9:50 pm
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?

Re: I2C implementation for STM32

Posted: Tue Aug 02, 2011 10:53 am
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?

Re: I2C implementation for STM32

Posted: Tue Aug 02, 2011 10:55 am
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

Re: I2C implementation for STM32

Posted: Tue Aug 02, 2011 6:21 pm
by barthess
What driver(s) looking for examples?

Re: I2C implementation for STM32

Posted: Tue Aug 02, 2011 6:37 pm
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

Re: I2C implementation for STM32

Posted: Fri Aug 05, 2011 11:45 am
by barthess
Hook added at revision 3189.

Re: I2C implementation for STM32

Posted: Tue Aug 23, 2011 9:57 am
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?

Re: I2C implementation for STM32

Posted: Tue Aug 23, 2011 11:13 am
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