Microchip® Advanced Software Framework

i2c_sam0/i2c_master.c File Reference

SAM I2C Master Driver.

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

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

Functions

enum status_code _i2c_master_address_response (struct i2c_master_module *const module)
 
static enum status_code _i2c_master_read_packet (struct i2c_master_module *const module, struct i2c_master_packet *const packet)
 
enum status_code _i2c_master_send_hs_master_code (struct i2c_master_module *const module, uint8_t hs_master_code)
 
enum status_code _i2c_master_wait_for_bus (struct i2c_master_module *const module)
 
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...
 

enum status_code _i2c_master_address_response ( struct i2c_master_module *const  module)
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_send_hs_master_code(), _i2c_master_wait_for_bus(), i2c_master_packet::address, Assert, i2c_master_packet::data, i2c_master_packet::data_length, i2c_master_packet::high_speed, i2c_master_packet::hs_master_code, I2C_TRANSFER_READ, STATUS_ERR_PACKET_COLLISION, STATUS_OK, and i2c_master_packet::ten_bit_address.

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

enum status_code _i2c_master_send_hs_master_code ( struct i2c_master_module *const  module,
uint8_t  hs_master_code 
)

Send master code for high speed transfer.

Parameters
[in,out]modulePointer to software module structure
[in]hs_master_code8-bit master code (0000 1XXX)
Returns
Status of bus.
Return values
STATUS_OKNo error happen

References _i2c_master_wait_for_bus().

Referenced by _i2c_master_read_packet(), and _i2c_master_write_packet().

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_send_hs_master_code(), _i2c_master_wait_for_bus(), i2c_master_packet::address, i2c_master_packet::data, i2c_master_packet::data_length, i2c_master_packet::high_speed, i2c_master_packet::hs_master_code, I2C_TRANSFER_WRITE, STATUS_ERR_OVERFLOW, STATUS_ERR_PACKET_COLLISION, STATUS_OK, and i2c_master_packet::ten_bit_address.

Referenced by i2c_master_write_packet_wait(), and i2c_master_write_packet_wait_no_stop().