49 i2c_init(uint8_t port_sda, uint8_t pin_sda, uint8_t port_scl, uint8_t pin_scl,
80 ioc_set_sel(port_sda, pin_sda, IOC_PXX_SEL_I2C_CMSSDA);
81 ioc_set_sel(port_scl, pin_scl, IOC_PXX_SEL_I2C_CMSSCL);
99 REG(I2CM_CR) &= ~0x10;
106 REG(I2CM_TPR) = ((SYS_CTRL_SYS_CLOCK + (2 * 10 * freq) - 1) /
107 (2 * 10 * freq)) - 1;
114 REG(I2CM_SA) = ((slave_addr << 1) | 1);
116 REG(I2CM_SA) = (slave_addr << 1);
135 REG(I2CM_CTRL) = cmd;
143 return REG(I2CM_STAT) & I2CM_STAT_BUSY;
149 uint8_t temp = REG(I2CM_STAT);
150 if(temp & I2CM_STAT_BUSY) {
151 return I2C_MASTER_ERR_NONE;
152 }
else if(temp & (I2CM_STAT_ERROR | I2CM_STAT_ARBLST)) {
155 return I2C_MASTER_ERR_NONE;
181 if(temp == I2C_MASTER_ERR_NONE) {
191 if((len == 0) || (data == NULL)) {
192 return I2CM_STAT_INVALID;
202 for(sent = 1; sent <= (len - 2); sent++) {
221 if((len == 0) || data == NULL) {
222 return I2CM_STAT_INVALID;
233 for(recv = 1; recv <= (len - 2); recv++) {
uint8_t i2c_master_data_get(void)
Return received data from I2C.
#define SYS_CTRL_RCGCI2C
I2C clocks - active mode.
uint8_t i2c_master_busy(void)
Return the busy state of I2C module.
Header file for the cc2538 System Control driver.
void i2c_set_frequency(uint32_t freq)
Initialize I2C peripheral clock with given frequency.
void i2c_master_data_put(uint8_t data)
Prepare data to be transmitted.
uint8_t i2c_burst_send(uint8_t slave_addr, uint8_t *data, uint8_t len)
Perform all operations to send multiple bytes to a slave.
#define IOC_I2CMSSDA
I2C SDA.
void clock_delay_usec(uint16_t dt)
Delay a given number of microseconds.
#define IOC_OVERRIDE_DIS
Override Disabled.
#define GPIO_PIN_MASK(PIN)
Converts a pin number to a pin mask.
#define IOC_I2CMSSCL
I2C SCL.
uint8_t i2c_master_error(void)
Return the status register if error occurred during last communication.
void i2c_init(uint8_t port_sda, uint8_t pin_sda, uint8_t port_scl, uint8_t pin_scl, uint32_t bus_speed)
Initialize the I2C peripheral and pins.
void i2c_master_disable(void)
Disable master I2C module.
void ioc_set_over(uint8_t port, uint8_t pin, uint8_t over)
Set Port:Pin override function.
#define GPIO_SET_INPUT(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to input.
void i2c_master_command(uint8_t cmd)
Control the state of the master module for send and receive operations.
uint8_t i2c_burst_receive(uint8_t slave_addr, uint8_t *data, uint8_t len)
Perform all operations to receive multiple bytes from a slave.
void i2c_master_set_slave_address(uint8_t slave_addr, uint8_t access_mode)
Set the address of slave and access mode for the next I2C communication.
#define GPIO_PERIPHERAL_CONTROL(PORT_BASE, PIN_MASK)
Configure the pin to be under peripheral control with PIN_MASK of port with PORT_BASE.
uint8_t i2c_single_receive(uint8_t slave_addr, uint8_t *data)
Perform all operations to receive a byte from a slave.
#define ioc_input_sel(port, pin)
Generates an IOC_INPUT_SEL_PXn value from a port/pin number.
void ioc_set_sel(uint8_t port, uint8_t pin, uint8_t sel)
Function select for Port:Pin.
#define GPIO_PORT_TO_BASE(PORT)
Converts a port number to the port base address.
#define SYS_CTRL_SRI2C
I2C clocks - reset control.
uint8_t i2c_single_send(uint8_t slave_addr, uint8_t data)
Perform all operations to send a byte to a slave.
void i2c_master_enable(void)
Enable master I2C module.