librpipTransactionMsgAddRegRead

uint32_t librpipTransactionMsgAddRegRead(struct librpip_tx* t, uint8_t reg, uint16_t len);

Description

This function is a connivence for a specific use case – reading from a device that uses 8 bit registers as commonly found with I2C devices. It is simply creating the appropriate messages using librpipTransactionMsgAdd() for you. See librpipTransactionMsgAdd() for more details.

ie

librpipTransactionMsgAddRegRead(t, reg, len)

actually runs

librpipTransactionMsgAdd(t,LIBRPIP_TX_MSG_TX, &reg, 1);
librpipTransactionMsgAdd(t, LIBRPIP_TX_MSG_RX, 0,  len);

Parameters

  • struct librpip_tx* t
    A pointer to a transaction that is to have a messages added. This will have been created from a previous librpipTransactionCreate().
  • uint8_t reg
    The register to read from.
  • uint16_t len
    The length of the receive buffer.

Returns

0 on failure or 1 on success.

Example

Create a transaction to read some values from an I2C sensor using librpipTransactionMsgAddRegRead(). then do the same thing with a 2nd transaction using the librpipTransactionMsgAdd() function.

uint8_t reg;
struct librpip_tx* MySensor,My2ndSensor;
MySensor=librpipTransactionCreate(LIBRPIP_TX_MODE_I2C, 8);
librpipTransactionMsgAddRegRead(MySensor, 0x11, 3);
My2ndSensor=librpipTransactionCreate(LIBRPIP_TX_MODE_SPI, 8);
reg = 0x11;
librpipTransactionMsgAdd(My2ndSensor, LIBRPIP_TX_MSG_TX, &reg, 1);
librpipTransactionMsgAdd(My2ndSensor, LIBRPIP_TX_MSG_RX, 0, 3);

{ ... do something with MySensor and My2ndSensor ... }
librpipTransactionDestroy(MySensor); 
librpipTransactionDestroy(My2ndSensor); 
librpipClose();