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:
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
