Contiki-NG
Loading...
Searching...
No Matches

Files

file  i2c.c
 Implementation file of the I2C Control module.
 
file  i2c.h
 Header file with declarations for the I2C Control module.
 

I2C Functions

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_enable (void)
 Enable master I2C module.
 
void i2c_master_disable (void)
 Disable master I2C module.
 
void i2c_set_frequency (uint32_t freq)
 Initialize I2C peripheral clock with given frequency.
 
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.
 
void i2c_master_data_put (uint8_t data)
 Prepare data to be transmitted.
 
uint8_t i2c_master_data_get (void)
 Return received data from I2C.
 
void i2c_master_command (uint8_t cmd)
 Control the state of the master module for send and receive operations.
 
uint8_t i2c_master_busy (void)
 Return the busy state of I2C module.
 
uint8_t i2c_master_error (void)
 Return the status register if error occurred during last communication.
 
uint8_t i2c_single_send (uint8_t slave_addr, uint8_t data)
 Perform all operations to send a byte to a slave.
 
uint8_t i2c_single_receive (uint8_t slave_addr, uint8_t *data)
 Perform all operations to receive a byte from a slave.
 
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.
 
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.
 

Detailed Description

cc2538 I2C Control Module

Function Documentation

◆ i2c_burst_receive()

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.

Parameters
slave_addrThe address of the slave from which data are received
dataA pointer to store the received data
lenNumber of bytes to receive
Returns
Return the value of i2c_master_error() after the I2C operation

Definition at line 218 of file i2c.c.

References i2c_master_busy(), i2c_master_command(), i2c_master_data_get(), i2c_master_error(), i2c_master_set_slave_address(), and i2c_single_receive().

Referenced by pm_get_num_cycles(), pm_get_timeout(), pm_get_voltage(), pm_read_byte(), and tmp102_read().

◆ i2c_burst_send()

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.

Parameters
slave_addrThe address of the slave to which data are sent
dataA pointer to the data to send to the slave
lenNumber of bytes to send
Returns
Return the value of i2c_master_error() after the I2C operation

Definition at line 188 of file i2c.c.

References i2c_master_busy(), i2c_master_command(), i2c_master_data_put(), i2c_master_error(), i2c_master_set_slave_address(), and i2c_single_send().

Referenced by pm_reset_system(), pm_set_timeout(), and pm_write_byte().

◆ i2c_init()

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.

Parameters
port_sdaThe GPIO number of the pin used fort SDA
pin_sdaThe pin number used for SDA
port_sclThe GPIO number of the pin used fort SCL
pin_sclThe pin number used for SCL
bus_speedThe clock frequency used by I2C module

bus_speed can take the following values:

  • I2C_SCL_NORMAL_BUS_SPEED : 100KHz
  • I2C_SCL_FAST_BUS_SPEED : 400KHz

< I2C clocks - active mode

< I2C clocks - reset control

< I2C clocks - reset control

< GPIO_A

< Data direction register

< GPIO_A

< Data direction register

< GPIO_A

< Mode control select

< GPIO_A

< Mode control select

< Override Disabled

< Override Disabled

< I2C SDA

< I2C SCL

Definition at line 49 of file i2c.c.

References clock_delay_usec(), GPIO_PERIPHERAL_CONTROL, GPIO_PIN_MASK, GPIO_PORT_TO_BASE, GPIO_SET_INPUT, i2c_master_enable(), i2c_set_frequency(), IOC_I2CMSSCL, IOC_I2CMSSDA, ioc_input_sel, IOC_OVERRIDE_DIS, ioc_set_over(), ioc_set_sel(), SYS_CTRL_RCGCI2C, and SYS_CTRL_SRI2C.

Referenced by platform_init_stage_two(), pm_enable(), rtcc_init(), and tmp102_init().

◆ i2c_master_busy()

uint8_t i2c_master_busy ( void )

Return the busy state of I2C module.

Return values
0The I2C module is not busy
1The I2C module is busy

Definition at line 141 of file i2c.c.

Referenced by i2c_burst_receive(), i2c_burst_send(), i2c_single_receive(), and i2c_single_send().

◆ i2c_master_command()

void i2c_master_command ( uint8_t cmd)

Control the state of the master module for send and receive operations.

Parameters
cmdThe operation to perform

cmd can take the following values:

  • I2C_MASTER_CMD_SINGLE_SEND
  • I2C_MASTER_CMD_SINGLE_RECEIVE
  • I2C_MASTER_CMD_BURST_SEND_START
  • I2C_MASTER_CMD_BURST_SEND_CONT
  • I2C_MASTER_CMD_BURST_SEND_FINISH
  • I2C_MASTER_CMD_BURST_SEND_ERROR_STOP
  • I2C_MASTER_CMD_BURST_RECEIVE_START
  • I2C_MASTER_CMD_BURST_RECEIVE_CONT
  • I2C_MASTER_CMD_BURST_RECEIVE_FINISH
  • I2C_MASTER_CMD_BURST_RECEIVE_ERROR_STOP

Definition at line 133 of file i2c.c.

References clock_delay_usec().

Referenced by i2c_burst_receive(), i2c_burst_send(), i2c_single_receive(), and i2c_single_send().

◆ i2c_master_data_get()

uint8_t i2c_master_data_get ( void )

Return received data from I2C.

Returns
The byte received by I2C after à receive command

Definition at line 127 of file i2c.c.

Referenced by i2c_burst_receive(), and i2c_single_receive().

◆ i2c_master_data_put()

void i2c_master_data_put ( uint8_t data)

Prepare data to be transmitted.

Parameters
dataThe byte of data to be transmitted from the I2C master

Definition at line 121 of file i2c.c.

Referenced by i2c_burst_send(), and i2c_single_send().

◆ i2c_master_error()

uint8_t i2c_master_error ( void )

Return the status register if error occurred during last communication.

Return values
I2C_MASTER_ERR_NONEReturn 0 if no error occurred

If an error occurred, return the status register of the I2C module. Use the result with the I2CM_STAT_* flags to custom your processing

Definition at line 147 of file i2c.c.

Referenced by i2c_burst_receive(), i2c_burst_send(), i2c_single_receive(), i2c_single_send(), and tmp102_read().

◆ i2c_master_set_slave_address()

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.

Parameters
slave_addrThe receiver slave address on 7 bits
access_modeThe I2C access mode (send/receive)

access_mode can take the following values:

  • I2C_RECEIVE : 1
  • I2C_SEND : 0

Definition at line 111 of file i2c.c.

Referenced by i2c_burst_receive(), i2c_burst_send(), i2c_single_receive(), and i2c_single_send().

◆ i2c_set_frequency()

void i2c_set_frequency ( uint32_t freq)

Initialize I2C peripheral clock with given frequency.

Parameters
freqThe desired frequency

freq can take the following values:

  • I2C_SCL_NORMAL_BUS_SPEED : 100KHz
  • I2C_SCL_FAST_BUS_SPEED : 400KHz

Definition at line 103 of file i2c.c.

Referenced by i2c_init().

◆ i2c_single_receive()

uint8_t i2c_single_receive ( uint8_t slave_addr,
uint8_t * data )

Perform all operations to receive a byte from a slave.

Parameters
slave_addrThe address of the slave from which data are received
dataA pointer to store the received data
Returns
Return the value of i2c_master_error() after the I2C operation

Definition at line 172 of file i2c.c.

References i2c_master_busy(), i2c_master_command(), i2c_master_data_get(), i2c_master_error(), and i2c_master_set_slave_address().

Referenced by i2c_burst_receive().

◆ i2c_single_send()

uint8_t i2c_single_send ( uint8_t slave_addr,
uint8_t data )

Perform all operations to send a byte to a slave.

Parameters
slave_addrThe adress of the slave to which data are sent
dataThe data to send to the slave
Returns
Return the value of i2c_master_error() after the I2C operation

Definition at line 159 of file i2c.c.

References i2c_master_busy(), i2c_master_command(), i2c_master_data_put(), i2c_master_error(), and i2c_master_set_slave_address().

Referenced by i2c_burst_send(), pm_get_num_cycles(), pm_get_timeout(), pm_get_voltage(), pm_read_byte(), and tmp102_read().