i2c(3)
π i2c β I2C access π
okay bestie, welcome to the i2c(3) page from the bcm2835 library manual β yes, it's a section 3 (library functions) situation, and yes it's giving "I talk to tiny chips over two wires" energy. let's go π¦
β¨ NAME β¨
i2c β I2C access. that's it. that's the whole name. short, iconic, no notes π
πΈ SYNOPSIS πΈ
π Functions
int bcm2835_i2c_begin (void)
void bcm2835_i2c_end (void)
void bcm2835_i2c_setSlaveAddress (uint8_t addr)
void bcm2835_i2c_setClockDivider (uint16_t divider)
void bcm2835_i2c_set_baudrate (uint32_t baudrate)
uint8_t bcm2835_i2c_write (const char *buf, uint32_t len)
uint8_t bcm2835_i2c_read (char *buf, uint32_t len)
uint8_t bcm2835_i2c_read_register_rs (char *regaddr, char *buf, uint32_t len)
uint8_t bcm2835_i2c_write_read_rs (char *cmds, uint32_t cmds_len, char *buf, uint32_t buf_len)
π«Ά Detailed Description π«Ά
These functions let you use I2C (The Broadcom Serial Control bus with the Philips I2C bus/interface version 2.1 January 2000.) to interface with an external I2C device.
fr fr, that's the whole plot: two little wires, one big vibe, and an external chip that finally gets to say something. iconic honestly β¨
π Function Documentation π
π int bcm2835_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
like. it literally flips the pins into I2C mode. ALT0 or nothing, bestie.
Returns
1 if successful, 0 otherwise (perhaps because you are not running as root)
not root? you get a 0. it's not a you problem, it's a permissions problem. π
See also
bcm2835_i2c_end()
πΈ void bcm2835_i2c_end (void) [extern]
End I2C operations. I2C pins P1-03 (SDA) and P1-05 (SCL) are returned to their default INPUT behaviour.
the clean exit. the graceful goodbye. pins go back to being plain old INPUTs, no I2C main character energy anymore. π
π¦ uint8_t bcm2835_i2c_read (char * buf, uint32_t len) [extern]
Transfers any number of bytes from the currently selected I2C slave. (as previously set by
See also
bcm2835_i2c_setSlaveAddress)
Parameters
bufβ Buffer of bytes to receive.lenβ Number of bytes in thebufbuffer, and the number of bytes to received.
Returns
reason β see bcm2835I2CReasonCodes
π uint8_t bcm2835_i2c_read_register_rs (char * regaddr, char * buf, uint32_t len) [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:
See also
bcm2835_i2c_write
bcm2835_i2c_read are a better choice. Will read from the slave previously set by
bcm2835_i2c_setSlaveAddress
Parameters
regaddrβ Buffer containing the slave register you wish to read from.bufβ Buffer of bytes to receive.lenβ Number of bytes in thebufbuffer, and the number of bytes to received.
Returns
reason β see bcm2835I2CReasonCodes
β void bcm2835_i2c_set_baudrate (uint32_t baudrate) [extern]
Sets the I2C clock divider by converting the baudrate parameter to the equivalent I2C clock divider. ( see
See also
bcm2835_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)
so you hand it a baudrate and it does the divider math for you. 100khz? that's 100000. easy. π§
π void bcm2835_i2c_setClockDivider (uint16_t divider) [extern]
Sets the I2C clock divider and therefore the I2C clock speed.
Parameters
dividerβ The desired I2C clock divider, one ofBCM2835_I2C_CLOCK_DIVIDER_*, seebcm2835I2CClockDivider
π void bcm2835_i2c_setSlaveAddress (uint8_t addr) [extern]
Sets the I2C slave address.
Parameters
addrβ The I2C slave address.
short and sweet and it sets the whole vibe of who you're talking to. π
β¨ uint8_t bcm2835_i2c_write (const char * buf, uint32_t len) [extern]
Transfers any number of bytes to the currently selected I2C slave. (as previously set by
See also
bcm2835_i2c_setSlaveAddress)
Parameters
bufβ Buffer of bytes to send.lenβ Number of bytes in thebufbuffer, and the number of bytes to send.
Returns
reason β see bcm2835I2CReasonCodes
π uint8_t bcm2835_i2c_write_read_rs (char * cmds, uint32_t cmds_len, char * buf, uint32_t buf_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
See also
bcm2835_i2c_setSlaveAddress
Parameters
cmdsβ Buffer containing the bytes to send before the repeated start condition.cmds_lenβ Number of bytes to send fromcmdsbufferbufβ Buffer of bytes to receive.buf_lenβ Number of bytes to receive in thebufbuffer.
Returns
reason β see bcm2835I2CReasonCodes
π Author π
Generated automatically by Doxygen for bcm2835 from the source code.
lowkey the most impressive thing here is that a robot (Doxygen) wrote the author section and nobody's mad about it. π
and that's the whole page bestie, we ate and left no crumbs. this was bcm2835 Version 1.75, dated i2c(3) β manual page for the bcm2835 library functions manual. mwah π
πβ¨
π¦ where this page comes from
- debian trixie: libbcm2835-dev 1.75+ds-1 Β· GPL-3.0-only
- ubuntu noble: libbcm2835-dev 1.75+ds-1 Β· GPL-3.0-only
- ubuntu questing: libbcm2835-dev 1.75+ds-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms