Microchip® Advanced Software Framework

i2c_samd20/i2c_master.c File Reference

SAM D20 I2C Master Driver.

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

#include "i2c_master.h"
#include "i2c_master_interrupt.h"

Functions

static enum status_code _i2c_master_read_packet (struct i2c_master_module *const module, struct i2c_master_packet *const packet)
 
static enum status_code _i2c_master_write_packet (struct i2c_master_module *const module, struct i2c_master_packet *const packet)
 
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...
 
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_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_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...
 
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...
 
void i2c_master_reset (struct i2c_master_module *const module)
 Resets the hardware module. More...
 
void i2c_master_send_nack (struct i2c_master_module *const module)
 Sends nack signal on bus. More...
 
void i2c_master_send_stop (struct i2c_master_module *const module)
 Sends stop condition on bus. 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_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...
 

static enum status_code _i2c_master_read_packet ( struct i2c_master_module *const  module,
struct i2c_master_packet *const  packet 
)
static

Starts blocking read operation.

Parameters
[in,out]modulePointer to software module struct
[in,out]packetPointer to I2C packet to transfer
Returns
Status of reading packet.
Return values
STATUS_OKThe packet was read successfully
STATUS_ERR_TIMEOUTIf no response was given within specified timeout period
STATUS_ERR_DENIEDIf error on bus
STATUS_ERR_PACKET_COLLISIONIf arbitration is lost
STATUS_ERR_BAD_ADDRESSIf slave is busy, or no slave acknowledged the address

References _i2c_master_address_response(), _i2c_master_wait_for_bus(), i2c_master_packet::address, Assert, counter, i2c_master_packet::data, i2c_master_packet::data_length, I2C_TRANSFER_READ, STATUS_ERR_PACKET_COLLISION, and STATUS_OK.

Referenced by i2c_master_read_packet_wait(), i2c_master_read_packet_wait_no_nack(), and i2c_master_read_packet_wait_no_stop().

static enum status_code _i2c_master_write_packet ( struct i2c_master_module *const  module,
struct i2c_master_packet *const  packet 
)
static

Starts blocking write operation.

Parameters
[in,out]modulePointer to software module struct
[in,out]packetPointer to I2C packet to transfer
Returns
Status of write packet.
Return values
STATUS_OKThe packet was write successfully
STATUS_ERR_TIMEOUTIf no response was given within specified timeout period
STATUS_ERR_DENIEDIf error on bus
STATUS_ERR_PACKET_COLLISIONIf arbitration is lost
STATUS_ERR_BAD_ADDRESSIf slave is busy, or no slave acknowledged the address

References _i2c_master_address_response(), _i2c_master_wait_for_bus(), i2c_master_packet::address, i2c_master_packet::data, i2c_master_packet::data_length, I2C_TRANSFER_WRITE, STATUS_ERR_OVERFLOW, STATUS_ERR_PACKET_COLLISION, and STATUS_OK.

Referenced by i2c_master_write_packet_wait(), and i2c_master_write_packet_wait_no_stop().