librpipTransactionMsgAddRegWrite
uint32_t librpipTransactionMsgAddRegWrite(struct librpip_tx* t, uint8_t reg, uint8_t value);
Description
This function is a connivence for a specific use case – writing an 8 bit word to a device that uses 8 bit registers as commonly found with I2C devices. It is simply creating the appropriate message using librpipTransactionMsgAdd() for you. See librpipTransactionMsgAdd() for more details.
ie
librpipTransactionMsgAddRegWrite(t, reg, value)
actually runs
buf[0]=reg; buf[1]=value; librpipTransactionMsgAdd(t,LIBRPIP_TX_MSG_TX, &buf, 2);
Parameters
- struct librpip_tx* t
A pointer to a transaction that is to have a message added. This will have been created from a previous librpipTransactionCreate(). - uint8_t reg
The register to write to. - uint16_t value
The value to write.
Returns
0 on failure or 1 on success.
Example
Create a transaction to write some values to an I2C sensor using librpipTransactionMsgAddRegWrite(). then do the same thing with a 2nd transaction using the librpipTransactionMsgAdd() function.
uint8_t buf[2]; struct librpip_tx* MySensor,My2ndSensor; MySensor=librpipTransactionCreate(LIBRPIP_TX_MODE_I2C, 8); librpipTransactionMsgAddRegWrite(MySensor, 0x11, 0x31); My2ndSensor=librpipTransactionCreate(LIBRPIP_TX_MODE_SPI, 8); buf[0] = 0x11; buf[1] = 0x31; librpipTransactionMsgAdd(My2ndSensor, LIBRPIP_TX_MSG_TX, &buf, 2); { ... do something with MySensor and My2ndSensor ... } librpipTransactionDestroy(MySensor); librpipTransactionDestroy(My2ndSensor); librpipClose();