I2C implementation for STM32
Re: I2C implementation for STM32
Looks like no feedback for a moment.
Giovanni, can I perform merge to trunk, or only you can commit to trunk?
Giovanni, can I perform merge to trunk, or only you can commit to trunk?
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: I2C implementation for STM32
You can commit to trunk, please just change I2C related files, I am still moving STM32 stuff around.
Giovanni
Giovanni
Re: I2C implementation for STM32
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.
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: I2C implementation for STM32
The I2C code would not be impacted, put the low level driver under ./os/hal/platforms/STM32 as usual.
Giovanni
Giovanni
-
DrunkenDonkey
- Posts: 124
- Joined: Sun Aug 28, 2011 5:16 pm
Re: I2C implementation for STM32
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 
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:
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:
Or the proper way to do is
I totally understand I'm asking very newbie questions, sorry for that
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
First of all, driver can not work without callback for a moment. So you must set
Your second way is proper.
But may be device specific. What your device is?
Code: Select all
#define I2C_SUPPORTS_CALLBACKS TRUEYour 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 dataBut may be device specific. What your device is?
-
DrunkenDonkey
- Posts: 124
- Joined: Sun Aug 28, 2011 5:16 pm
Re: I2C implementation for STM32
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
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
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
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
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
Check rev. 3306. Now it is not const.
UPDATE:
rev. 3307