Page 13 of 35

Re: I2C implementation for STM32

Posted: Sun Aug 28, 2011 11:14 am
by barthess
Looks like no feedback for a moment.
Giovanni, can I perform merge to trunk, or only you can commit to trunk?

Re: I2C implementation for STM32

Posted: Sun Aug 28, 2011 11:28 am
by Giovanni
You can commit to trunk, please just change I2C related files, I am still moving STM32 stuff around.

Giovanni

Re: I2C implementation for STM32

Posted: Sun Aug 28, 2011 11:59 am
by barthess
I am still moving STM32 stuff around

Hm... It is better to postpone merging until STM32 code stop moving. Let me know when you are finished.

Re: I2C implementation for STM32

Posted: Sun Aug 28, 2011 12:20 pm
by Giovanni
The I2C code would not be impacted, put the low level driver under ./os/hal/platforms/STM32 as usual.

Giovanni

Re: I2C implementation for STM32

Posted: Sun Aug 28, 2011 5:57 pm
by DrunkenDonkey
Hey guys, I'm a few days reader on this forum, never ever touched embedded development before, still a week till my kit comes, but I have set some eclipse/G++ and using the time to fell in love with ChibiOS :D
I must say stuff looks kinda confusing from the start, but Chibi is a massive help, many thanks for it!

For good or bad, I started learning what i2c is first, checked the i2c source on that branch (great news about merging it to the trunk) and while I sorta understand how the stuff works from a hardware standpoint, I'm not sure about the current implementation... considering I will have a gadget that have... "registers" that I can read/write to, and I need access to several of them at once for a single operation, I considered the blocking approach:

#define HAL_USE_I2C TRUE
#define I2C_SUPPORTS_CALLBACKS FALSE
#define I2C_USE_WAIT TRUE

So I guess a code to write to a register will be:

Code: Select all

i2cAcquireBus(&I2CD1);
tx_data[0]=register;
tx_data[1]=data;
i2cMasterTransmit(&I2CD1,&i2cSlaveConfig,slave_addr,tx_data,2,rx_data,0);
i2cReleaseBus(&I2CD1);
//proceed to more transmit/receive


But what will be the code to read from it since by i2c specs I have to "write" before reading... looking at the code transmit function is filling the structs, then some interrupt handler pokes with them, but I can't tell if after MasterTransmit operation the data will be already in the rx buffer, or do I need to do a separate reading, i.e. should I do:

Code: Select all

i2cAcquireBus(&I2CD1);
tx_data[0]=register;
i2cMasterTransmit(&I2CD1,&i2cSlaveConfig,slave_addr,tx_data,1,rx_data,0);
i2cMasterReceive(&I2CD1,&i2cSlaveConfig,slave_addr,rx_data,2);
i2cReleaseBus(&I2CD1);
//do something with the data


Or the proper way to do is

Code: Select all

i2cAcquireBus(&I2CD1);
tx_data[0]=register;
i2cMasterTransmit(&I2CD1,&i2cSlaveConfig,slave_addr,tx_data,1,rx_data,2);
i2cReleaseBus(&I2CD1);
//do something with the data


I totally understand I'm asking very newbie questions, sorry for that :(

Re: I2C implementation for STM32

Posted: Sun Aug 28, 2011 6:29 pm
by barthess
First of all, driver can not work without callback for a moment. So you must set

Code: Select all

#define I2C_SUPPORTS_CALLBACKS TRUE


Your second way is proper.

Code: Select all

i2cAcquireBus(&I2CD1);
tx_data[0]=register;
i2cMasterTransmit(&I2CD1,&i2cSlaveConfig,slave_addr,tx_data,1,rx_data,2);
i2cReleaseBus(&I2CD1);
//do something with the data


But may be device specific. What your device is?

Re: I2C implementation for STM32

Posted: Sun Aug 28, 2011 6:43 pm
by DrunkenDonkey
Thanks for response barthess. I want to poke with iphone authentication chip, it have quite clean protocol. So, having callbacks on, is it possible the i2c driver to work synchronous, i.e. I2C_USE_WAIT still have an effect right, so I can leave the callbacks there feeling empty, but can still have multiple i2cMasterTransmit with/without receive one after another? That would be so great.

Re: I2C implementation for STM32

Posted: Sun Aug 28, 2011 6:57 pm
by barthess
i.e. I2C_USE_WAIT still have an effect right, so I can leave the callbacks there feeling empty, but can still have multiple i2cMasterTransmit with/without receive one after another?

That's right. If not sure - you can switch mutual exclusion on and surround calls by i2cAcquireBus i2cReleaseBus clause.

Re: I2C implementation for STM32

Posted: Sun Sep 11, 2011 5:25 pm
by Badger
I have a request. I originally requested a hook in I2CSlaveConfig because I wanted to store (changing) information about the slave devices that would be accessible in the callback functions. After much frustration I realised that this was causing me headaches because I2CDriver.id_slave_config is const I2CSlaveConfig. Could it be changed such that the two callback pointers in I2CSlaveConfig are const, but not the structure itself?

I can get around this restriction if we have a hook for extra fields in I2CDriver (this would probably be useful regardless), but as the information relates to the slave rather than the driver I don't think this is such an elegant solution ;)

Re: I2C implementation for STM32

Posted: Sun Sep 11, 2011 7:20 pm
by barthess
Technically this is not a problem and initially that pointer was not const. Const qualifier was set to save couple of bytes.
Check rev. 3306. Now it is not const.

UPDATE:
rev. 3307