Microchip® Advanced Software Framework

i2c_master.h File Reference

SAM SERCOM I2C Master Driver.

Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.

#include "i2c_common.h"
#include <sercom.h>
#include <pinmux.h>
#include <sercom_interrupt.h>

Data Structures

struct  i2c_master_config
 Configuration structure for the I2C Master device. More...
 
struct  i2c_master_module
 SERCOM I2C Master driver software device instance structure. More...
 
struct  i2c_master_packet
 I2C master packet for read/write. More...
 

Macros

#define PINMUX_DEFAULT   0
 

Enumerations

enum  i2c_master_baud_rate {
  I2C_MASTER_BAUD_RATE_100KHZ = 100,
  I2C_MASTER_BAUD_RATE_400KHZ = 400,
  I2C_MASTER_BAUD_RATE_1000KHZ = 1000,
  I2C_MASTER_BAUD_RATE_3400KHZ = 3400
}
 I2C frequencies. More...
 
enum  i2c_master_callback {
  I2C_MASTER_CALLBACK_WRITE_COMPLETE = 0,
  I2C_MASTER_CALLBACK_READ_COMPLETE = 1,
  I2C_MASTER_CALLBACK_ERROR = 2
}
 Callback types. More...
 
enum  i2c_master_inactive_timeout {
  I2C_MASTER_INACTIVE_TIMEOUT_DISABLED = SERCOM_I2CM_CTRLA_INACTOUT(0),
  I2C_MASTER_INACTIVE_TIMEOUT_55US = SERCOM_I2CM_CTRLA_INACTOUT(1),
  I2C_MASTER_INACTIVE_TIMEOUT_105US = SERCOM_I2CM_CTRLA_INACTOUT(2),
  I2C_MASTER_INACTIVE_TIMEOUT_205US = SERCOM_I2CM_CTRLA_INACTOUT(3)
}
 Values for inactive bus time-out. More...
 
enum  i2c_master_interrupt_flag {
  I2C_MASTER_INTERRUPT_WRITE = 0,
  I2C_MASTER_INTERRUPT_READ = 1
}
 Interrupt flags. More...
 
enum  i2c_master_start_hold_time {
  I2C_MASTER_START_HOLD_TIME_DISABLED = SERCOM_I2CM_CTRLA_SDAHOLD(0),
  I2C_MASTER_START_HOLD_TIME_50NS_100NS = SERCOM_I2CM_CTRLA_SDAHOLD(1),
  I2C_MASTER_START_HOLD_TIME_300NS_600NS = SERCOM_I2CM_CTRLA_SDAHOLD(2),
  I2C_MASTER_START_HOLD_TIME_400NS_800NS = SERCOM_I2CM_CTRLA_SDAHOLD(3)
}
 Values for hold time after start bit. More...
 
enum  i2c_master_transfer_speed {
  I2C_MASTER_SPEED_STANDARD_AND_FAST = SERCOM_I2CM_CTRLA_SPEED(0),
  I2C_MASTER_SPEED_FAST_MODE_PLUS = SERCOM_I2CM_CTRLA_SPEED(1),
  I2C_MASTER_SPEED_HIGH_SPEED = SERCOM_I2CM_CTRLA_SPEED(2)
}
 Enum for the transfer speed. More...
 

Functions

Lock/Unlock
static enum status_code i2c_master_lock (struct i2c_master_module *const module)
 Attempt to get lock on driver instance. More...
 
static void i2c_master_unlock (struct i2c_master_module *const module)
 Unlock driver instance. More...
 
Configuration and Initialization
static bool i2c_master_is_syncing (const struct i2c_master_module *const module)
 Returns the synchronization status of the module. More...
 
static void i2c_master_get_config_defaults (struct i2c_master_config *const config)
 Gets the I2C master default configurations. More...
 
enum status_code i2c_master_init (struct i2c_master_module *const module, Sercom *const hw, const struct i2c_master_config *const config)
 Initializes the requested I2C hardware module. More...
 
static void i2c_master_enable (const struct i2c_master_module *const module)
 Enables the I2C module. More...
 
static void i2c_master_disable (const struct i2c_master_module *const module)
 Disable the I2C module. More...
 
void i2c_master_reset (struct i2c_master_module *const module)
 Resets the hardware module. More...
 
Read and Write
enum status_code i2c_master_read_packet_wait (struct i2c_master_module *const module, struct i2c_master_packet *const packet)
 Reads data packet from slave. More...
 
enum status_code i2c_master_read_packet_wait_no_stop (struct i2c_master_module *const module, struct i2c_master_packet *const packet)
 Reads data packet from slave without sending a stop condition when done. More...
 
enum status_code i2c_master_write_packet_wait (struct i2c_master_module *const module, struct i2c_master_packet *const packet)
 Writes data packet to slave. More...
 
enum status_code i2c_master_write_packet_wait_no_stop (struct i2c_master_module *const module, struct i2c_master_packet *const packet)
 Writes data packet to slave without sending a stop condition when done. More...
 
void i2c_master_send_stop (struct i2c_master_module *const module)
 Sends stop condition on bus. More...
 
void i2c_master_send_nack (struct i2c_master_module *const module)
 Sends nack signal on bus. More...
 
enum status_code i2c_master_read_byte (struct i2c_master_module *const module, uint8_t *byte)
 Reads one byte data from slave. More...
 
enum status_code i2c_master_write_byte (struct i2c_master_module *const module, uint8_t byte)
 Write one byte data to slave. More...
 
enum status_code i2c_master_read_packet_wait_no_nack (struct i2c_master_module *const module, struct i2c_master_packet *const packet)
 Reads data packet from slave without sending a nack signal and a stop condition when done. More...
 
SERCOM I2C Master with DMA Interfaces
static void i2c_master_dma_set_transfer (struct i2c_master_module *const module, uint16_t addr, uint8_t length, enum i2c_transfer_direction direction)
 Set I2C for DMA transfer with slave address and transfer size. More...
 

#define PINMUX_DEFAULT   0