intbcm2835_i2c_begin(void)[extern]
Start I2C operations. Forces RPi I2C pins P1-03 (SDA) and P1-05 (SCL) to alternate function ALT0, which
enables those pins for I2C interface. You should call bcm2835_i2c_end() when all I2C functions are
complete to return the pins to their default functions
Returns
1 if successful, 0 otherwise (perhaps because you are not running as root)
Seealsobcm2835_i2c_end()voidbcm2835_i2c_end(void)[extern]
End I2C operations. I2C pins P1-03 (SDA) and P1-05 (SCL) are returned to their default INPUT behaviour.
uint8_tbcm2835_i2c_read(char*buf,uint32_tlen)[extern]
Transfers any number of bytes from the currently selected I2C slave. (as previously set by
Seealsobcm2835_i2c_setSlaveAddress)
Parametersbuf Buffer of bytes to receive.
len Number of bytes in the buf buffer, and the number of bytes to received.
Returns
reason see bcm2835I2CReasonCodesuint8_tbcm2835_i2c_read_register_rs(char*regaddr,char*buf,uint32_tlen)[extern]
Allows reading from I2C slaves that require a repeated start (without any prior stop) to read after the
required slave register has been set. For example, the popular MPL3115A2 pressure and temperature sensor.
Note that your device must support or require this mode. If your device does not require this mode then
the standard combined:
Seealsobcm2835_i2c_writebcm2835_i2c_read are a better choice. Will read from the slave previously set by
bcm2835_i2c_setSlaveAddressParametersregaddr Buffer containing the slave register you wish to read from.
buf Buffer of bytes to receive.
len Number of bytes in the buf buffer, and the number of bytes to received.
Returns
reason see bcm2835I2CReasonCodesvoidbcm2835_i2c_set_baudrate(uint32_tbaudrate)[extern]
Sets the I2C clock divider by converting the baudrate parameter to the equivalent I2C clock divider. (
see
Seealsobcm2835_i2c_setClockDivider) For the I2C standard 100khz you would set baudrate to 100000 The use of
baudrate corresponds to its use in the I2C kernel device driver. (Of course, bcm2835 has nothing to
do with the kernel driver)
voidbcm2835_i2c_setClockDivider(uint16_tdivider)[extern]
Sets the I2C clock divider and therefore the I2C clock speed.
Parametersdivider The desired I2C clock divider, one of BCM2835_I2C_CLOCK_DIVIDER_*, see bcm2835I2CClockDividervoidbcm2835_i2c_setSlaveAddress(uint8_taddr)[extern]
Sets the I2C slave address.
Parametersaddr The I2C slave address.
uint8_tbcm2835_i2c_write(constchar*buf,uint32_tlen)[extern]
Transfers any number of bytes to the currently selected I2C slave. (as previously set by
Seealsobcm2835_i2c_setSlaveAddress)
Parametersbuf Buffer of bytes to send.
len Number of bytes in the buf buffer, and the number of bytes to send.
Returns
reason see bcm2835I2CReasonCodesuint8_tbcm2835_i2c_write_read_rs(char*cmds,uint32_tcmds_len,char*buf,uint32_tbuf_len)[extern]
Allows sending an arbitrary number of bytes to I2C slaves before issuing a repeated start (with no prior
stop) and reading a response. Necessary for devices that require such behavior, such as the MLX90620.
Will write to and read from the slave previously set by
Seealsobcm2835_i2c_setSlaveAddressParameterscmds Buffer containing the bytes to send before the repeated start condition.
cmds_len Number of bytes to send from cmds buffer
buf Buffer of bytes to receive.
buf_len Number of bytes to receive in the buf buffer.
Returns
reason see bcm2835I2CReasonCodes