Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages

Macros

#define TWI_BAUD(F_SYS, F_TWI)   (((F_SYS / (2 * F_TWI)) - 5)+1)
 
#define TWI_SUCCESS   (STATUS_OK)
 Error Codes for the Module. More...
 

Functions

static void twi_master_disable (TWI_t *twi)
 Disable Master Mode of the TWI. More...
 
static void twi_master_enable (TWI_t *twi)
 Enable Master Mode of the TWI. More...
 
status_code_t twi_master_init (TWI_t *twi, const twi_options_t *opt)
 Initialize the twi master module. More...
 
static status_code_t twi_master_read (TWI_t *twi, const twi_package_t *package)
 Read multiple bytes from a TWI compatible slave device. More...
 
status_code_t twi_master_transfer (TWI_t *twi, const twi_package_t *package, bool read)
 Perform a TWI master write or read transfer. More...
 
static status_code_t twi_master_write (TWI_t *twi, const twi_package_t *package)
 Write multiple bytes to a TWI compatible slave device. More...
 

#define TWI_BAUD (   F_SYS,
  F_TWI 
)    (((F_SYS / (2 * F_TWI)) - 5)+1)

Baud register setting calculation. Formula described in datasheet.

Referenced by twi_master_setup(), and twi_slave_setup().

#define TWI_SUCCESS   (STATUS_OK)

Error Codes for the Module.

Deprecated:
This definition is provided for compatibility with existing ASF example applications. This module uses the status_code_t values that will replace module-specific error codes in ASF drivers.

Referenced by main().

static void twi_master_disable ( TWI_t *  twi)
inlinestatic

Disable Master Mode of the TWI.

Parameters
twiBase address of the TWI instance.
static void twi_master_enable ( TWI_t *  twi)
inlinestatic

Enable Master Mode of the TWI.

Parameters
twiBase address of the TWI instance.
status_code_t twi_master_init ( TWI_t *  twi,
const twi_options_t opt 
)

Initialize the twi master module.

Parameters
twiBase address of the TWI (i.e. &TWIC).
*optOptions for initializing the twi module (see twi_options_t)
Return values
STATUS_OKTransaction is successful
ERR_INVALID_ARGInvalid arguments in opt.

References CONF_PMIC_INTLVL, CONF_TWIM_INTLVL, cpu_irq_enable, twi_options_t::speed_reg, STATUS_OK, and transfer.

Referenced by twi_master_setup().

static status_code_t twi_master_read ( TWI_t *  twi,
const twi_package_t package 
)
inlinestatic

Read multiple bytes from a TWI compatible slave device.

Parameters
twiBase address of the TWI (i.e. &TWI_t).
packagePackage information and data (see twi_package_t)
Returns
STATUS_OK If all bytes were read, error code otherwise

References twi_master_transfer().

Referenced by main().

status_code_t twi_master_transfer ( TWI_t *  twi,
const twi_package_t package,
bool  read 
)

Perform a TWI master write or read transfer.

This function is a TWI Master write or read transaction.

Parameters
twiBase address of the TWI (i.e. &TWI_t).
packagePackage information and data (see twi_package_t)
readSelects the transfer direction
Returns
status_code_t
  • STATUS_OK if the transfer completes
  • ERR_BUSY to indicate an unavailable bus
  • ERR_IO_ERROR to indicate a bus transaction error
  • ERR_NO_MEMORY to indicate buffer errors
  • ERR_PROTOCOL to indicate an unexpected bus state
  • ERR_INVALID_ARG to indicate invalid arguments.

References twi_package_t::addr_length, twi_package_t::chip, ERR_INVALID_ARG, twi_package_t::no_wait, read, status, STATUS_OK, transfer, twim_acquire(), and twim_release().

Referenced by twi_master_read(), and twi_master_write().

static status_code_t twi_master_write ( TWI_t *  twi,
const twi_package_t package 
)
inlinestatic

Write multiple bytes to a TWI compatible slave device.

Parameters
twiBase address of the TWI (i.e. &TWI_t).
packagePackage information and data (see twi_package_t)
Returns
STATUS_OK If all bytes were written, error code otherwise

References twi_master_transfer().

Referenced by main().