High level I2C definitions.
More...
#include "hardware.h"
#include "global_defines.h"
#include <stdint.h>
Go to the source code of this file.
|
retval_t | i2c_init (void) |
|
retval_t | i2c_write_byte (uint8_t chip_addr, uint8_t reg_addr, uint8_t data) |
|
retval_t | i2c_write (uint8_t chip_addr, uint8_t start_adr, uint8_t *data_to_write_ptr, uint8_t data_len) |
|
retval_t | i2c_read_byte (uint8_t chip_addr, uint8_t start_adr, uint8_t *data_out_ptr) |
|
retval_t | i2c_read (uint8_t chip_addr, uint8_t start_adr, uint8_t *data_out_ptr, uint8_t data_len) |
|
High level I2C definitions.
◆ ACK
defines an acknowledge condition (low)
◆ I2C_MODE_READ
I2C read mode definition.
◆ I2C_MODE_WRITE
I2C write mode definition.
◆ I2C_RETRY_COUNT
#define I2C_RETRY_COUNT 3 |
◆ NACK
defines a neg-ack condition (high)
◆ i2c_init()
Initializes the I2C driver.
- Parameters
-
[out] | retval | (retval_t): Returns the initialization status of the I2C driver. |
◆ i2c_read()
retval_t i2c_read |
( |
uint8_t |
chip_addr, |
|
|
uint8_t |
start_adr, |
|
|
uint8_t * |
data_out_ptr, |
|
|
uint8_t |
data_len |
|
) |
| |
Reads N bytes from a chip. Handles starting and stopping of communication.
- Parameters
-
[in] | chip_addr | (uint8_t): The address of the chip to be read from. |
[in] | start_adr | (uint8_t): The starting register of the read. |
[in] | data_out_ptr | (uint8_t *): Location to store the read values. |
[in] | data_len | (uint8_t): amount of bytes to read. |
[out] | retval | (retval_t): Returns the success or failure of starting communication & reading the byte. |
◆ i2c_read_byte()
retval_t i2c_read_byte |
( |
uint8_t |
chip_addr, |
|
|
uint8_t |
start_adr, |
|
|
uint8_t * |
data_out_ptr |
|
) |
| |
Reads a byte from a chip. Handles starting and stopping of communication.
- Parameters
-
[in] | chip_addr | (uint8_t): The address of the chip to be read from. |
[in] | start_adr | (uint8_t): The starting register of the read. |
[in] | data_out_ptr | (uint8_t *): Location to store the read value. |
[out] | retval | (retval_t): Returns the success or failure of starting communication & reading the byte. |
◆ i2c_write()
retval_t i2c_write |
( |
uint8_t |
chip_addr, |
|
|
uint8_t |
start_adr, |
|
|
uint8_t * |
data_to_write_ptr, |
|
|
uint8_t |
data_len |
|
) |
| |
Starts communication with a chip and writes N bytes to the chip. Handles starting and ending communication as well.
- Parameters
-
[in] | chip_addr | (uint8_t): The address of the chip to be written to. |
[in] | start_adr | (uint8_t): The starting register of the write. |
[in] | data_to_write_ptr | (uint8_t *): The data to be written array. |
[in] | data_len | (uint8_t): How many bytes to be written. |
[out] | retval | (retval_t): Returns the success or failure of starting communication and writing to the device. |
◆ i2c_write_byte()
retval_t i2c_write_byte |
( |
uint8_t |
chip_addr, |
|
|
uint8_t |
reg_addr, |
|
|
uint8_t |
data |
|
) |
| |
Writes a byte to a chip. Handles starting and stopping of communication.
- Parameters
-
[in] | chip_addr | (uint8_t): The chip's address without the read/write bit set. |
[in] | reg_addr | (uint8_t): Address of the register you want to write to. |
[in] | data | (uint8_t): Data you want to write. |
[out] | retval | (retval_t): Returns the success or failure of starting communication & sending the byte. |