binary Clock
Macros | Functions
i2c.h File Reference

High level I2C definitions. More...

#include "hardware.h"
#include "global_defines.h"
#include <stdint.h>

Go to the source code of this file.

Macros

#define I2C_MODE_READ   1
 I2C read mode definition. More...
 
#define I2C_MODE_WRITE   0
 I2C write mode definition. More...
 
#define I2C_RETRY_COUNT   3
 number of times to retry More...
 
#define ACK   0
 defines an acknowledge condition (low) More...
 
#define NACK   1
 defines a neg-ack condition (high) More...
 

Functions

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)
 

Detailed Description

High level I2C definitions.

Macro Definition Documentation

◆ ACK

#define ACK   0

defines an acknowledge condition (low)

◆ I2C_MODE_READ

#define I2C_MODE_READ   1

I2C read mode definition.

◆ I2C_MODE_WRITE

#define I2C_MODE_WRITE   0

I2C write mode definition.

◆ I2C_RETRY_COUNT

#define I2C_RETRY_COUNT   3

number of times to retry

◆ NACK

#define NACK   1

defines a neg-ack condition (high)

Function Documentation

◆ i2c_init()

retval_t i2c_init ( void  )

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.