Microchip® Advanced Software Framework

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

Data Structures

struct  TWI_Slave
 TWI slave driver struct. More...
 

Macros

#define TWI_BAUD(F_SYS, F_TWI)   ((F_SYS / (2 * F_TWI)) - 5)
 
#define TWIS_RECEIVE_BUFFER_SIZE   8
 
#define TWIS_SEND_BUFFER_SIZE   8
 
#define TWIS_STATUS_BUSY   1
 
#define TWIS_STATUS_READY   0
 

Typedefs

typedef struct TWI_Slave TWI_Slave_t
 TWI slave driver struct. More...
 
typedef enum TWIS_RESULT_enum TWIS_RESULT_t
 

Enumerations

enum  TWIS_RESULT_enum {
  TWIS_RESULT_UNKNOWN = (0x00<<0),
  TWIS_RESULT_OK = (0x01<<0),
  TWIS_RESULT_BUFFER_OVERFLOW = (0x02<<0),
  TWIS_RESULT_TRANSMIT_COLLISION = (0x03<<0),
  TWIS_RESULT_BUS_ERROR = (0x04<<0),
  TWIS_RESULT_FAIL = (0x05<<0),
  TWIS_RESULT_ABORTED = (0x06<<0)
}
 

Functions

static void twi_slave_disable (TWI_t *twi)
 Disable Slave Mode of the TWI. More...
 
static void twi_slave_enable (TWI_t *twi)
 Enable Slave Mode of the TWI. More...
 
void TWI_SlaveAddressMatchHandler (TWI_Slave_t *twi)
 TWI address match interrupt handler. More...
 
void TWI_SlaveDataHandler (TWI_Slave_t *twi)
 TWI data interrupt handler. More...
 
void TWI_SlaveInitializeDriver (TWI_Slave_t *twi, TWI_t *module, void(*processDataFunction)(void))
 Initalizes TWI slave driver structure. More...
 
void TWI_SlaveInitializeModule (TWI_Slave_t *twi, uint8_t address, TWI_SLAVE_INTLVL_t intLevel)
 Initialize the TWI module. More...
 
void TWI_SlaveInterruptHandler (TWI_Slave_t *twi)
 Common TWI slave interrupt service routine. More...
 
void TWI_SlaveReadHandler (TWI_Slave_t *twi)
 TWI slave read interrupt handler. More...
 
void TWI_SlaveStopHandler (TWI_Slave_t *twi)
 TWI stop condition interrupt handler. More...
 
void TWI_SlaveTransactionFinished (TWI_Slave_t *twi, uint8_t result)
 TWI transaction finished function. More...
 
void TWI_SlaveWriteHandler (TWI_Slave_t *twi)
 TWI slave write interrupt handler. More...
 

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

Baud register setting calculation. Formula described in datasheet.

#define TWIS_RECEIVE_BUFFER_SIZE   8

Referenced by TWI_SlaveReadHandler().

#define TWIS_SEND_BUFFER_SIZE   8
#define TWIS_STATUS_BUSY   1
#define TWIS_STATUS_READY   0

typedef struct TWI_Slave TWI_Slave_t

TWI slave driver struct.

TWI slave struct. Holds pointer to TWI module and data processing routine, buffers and necessary variables.

Enumerator
TWIS_RESULT_UNKNOWN 
TWIS_RESULT_OK 
TWIS_RESULT_BUFFER_OVERFLOW 
TWIS_RESULT_TRANSMIT_COLLISION 
TWIS_RESULT_BUS_ERROR 
TWIS_RESULT_FAIL 
TWIS_RESULT_ABORTED 

static void twi_slave_disable ( TWI_t *  twi)
inlinestatic

Disable Slave Mode of the TWI.

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

Enable Slave Mode of the TWI.

TWI slave interrupt service routine.

Interrupt service routine for the TWI slave. Copy the interrupt vector into your code if needed.

ISR(TWIC_TWIS_vect) { TWI_SlaveInterruptHandler(&twiSlaveC); }

Parameters
twiBase address of the TWI instance.
void TWI_SlaveAddressMatchHandler ( TWI_Slave_t twi)

TWI address match interrupt handler.

Prepares TWI module for transaction when an address match occurs.

Parameters
twiThe TWI_Slave_t struct instance.

References TWI_Slave::abort, TWI_Slave::bytesReceived, TWI_Slave::bytesSent, TWI_Slave::interface, TWI_Slave::result, TWI_Slave::status, TWI_SlaveTransactionFinished(), TWIS_RESULT_ABORTED, TWIS_RESULT_UNKNOWN, and TWIS_STATUS_BUSY.

Referenced by TWI_SlaveInterruptHandler().

void TWI_SlaveDataHandler ( TWI_Slave_t twi)

TWI data interrupt handler.

Calls the appropriate slave read or write handler.

Parameters
twiThe TWI_Slave_t struct instance.

References TWI_Slave::interface, TWI_SlaveReadHandler(), and TWI_SlaveWriteHandler().

Referenced by TWI_SlaveInterruptHandler().

void TWI_SlaveInitializeDriver ( TWI_Slave_t twi,
TWI_t *  module,
void(*)(void)  processDataFunction 
)

Initalizes TWI slave driver structure.

Initialize the instance of the TWI Slave and set the appropriate values.

Parameters
twiThe TWI_Slave_t struct instance.
modulePointer to the TWI module.
processDataFunctionPointer to the function that handles incoming data.

References TWI_Slave::abort, TWI_Slave::bytesReceived, TWI_Slave::bytesSent, TWI_Slave::interface, TWI_Slave::Process_Data, TWI_Slave::result, TWI_Slave::status, TWIS_RESULT_UNKNOWN, and TWIS_STATUS_READY.

Referenced by run_twi_master_recv_test(), run_twi_master_send_test(), run_twi_slave_recv_test(), and twi_slave_setup().

void TWI_SlaveInitializeModule ( TWI_Slave_t twi,
uint8_t  address,
TWI_SLAVE_INTLVL_t  intLevel 
)

Initialize the TWI module.

Enables interrupts on address recognition and data available. Remember to enable interrupts globally from the main application.

Parameters
twiThe TWI_Slave_t struct instance.
addressSlave address for this module.
intLevelInterrupt level for the TWI slave interrupt handler.

References TWI_Slave::interface.

Referenced by run_twi_master_recv_test(), run_twi_master_send_test(), run_twi_slave_recv_test(), and twi_slave_setup().

void TWI_SlaveInterruptHandler ( TWI_Slave_t twi)

Common TWI slave interrupt service routine.

Handles all TWI transactions and responses to address match, data reception, data transmission, bus error and data collision.

Parameters
twiThe TWI_Slave_t struct instance.

References TWI_Slave::bytesReceived, TWI_Slave::bytesSent, TWI_Slave::interface, TWI_Slave::result, TWI_Slave::status, TWI_SlaveAddressMatchHandler(), TWI_SlaveDataHandler(), TWI_SlaveStopHandler(), TWI_SlaveTransactionFinished(), TWIS_RESULT_BUS_ERROR, TWIS_RESULT_FAIL, TWIS_RESULT_TRANSMIT_COLLISION, and TWIS_STATUS_READY.

Referenced by ISR().

void TWI_SlaveReadHandler ( TWI_Slave_t twi)

TWI slave read interrupt handler.

Handles TWI slave read transactions and responses.

Parameters
twiThe TWI_Slave_t struct instance.

References TWI_Slave::abort, TWI_Slave::bytesReceived, data, TWI_Slave::interface, TWI_Slave::Process_Data, TWI_Slave::receivedData, TWI_SlaveTransactionFinished(), TWIS_RECEIVE_BUFFER_SIZE, TWIS_RESULT_ABORTED, and TWIS_RESULT_BUFFER_OVERFLOW.

Referenced by TWI_SlaveDataHandler().

void TWI_SlaveStopHandler ( TWI_Slave_t twi)

TWI stop condition interrupt handler.

Parameters
twiThe TWI_Slave_t struct instance.

References TWI_Slave::interface, TWI_SlaveTransactionFinished(), and TWIS_RESULT_OK.

Referenced by TWI_SlaveInterruptHandler().

void TWI_SlaveTransactionFinished ( TWI_Slave_t twi,
uint8_t  result 
)

TWI transaction finished function.

Prepares module for new transaction.

Parameters
twiThe TWI_Slave_t struct instance.
resultThe result of the transaction.

References TWI_Slave::result, TWI_Slave::status, and TWIS_STATUS_READY.

Referenced by TWI_SlaveAddressMatchHandler(), TWI_SlaveInterruptHandler(), TWI_SlaveReadHandler(), TWI_SlaveStopHandler(), and TWI_SlaveWriteHandler().

void TWI_SlaveWriteHandler ( TWI_Slave_t twi)

TWI slave write interrupt handler.

Handles TWI slave write transactions and responses.

Parameters
twiThe TWI_Slave_t struct instance.

References TWI_Slave::bytesSent, data, TWI_Slave::interface, TWI_Slave::sendData, TWI_SlaveTransactionFinished(), TWIS_RESULT_BUFFER_OVERFLOW, TWIS_RESULT_OK, and TWIS_SEND_BUFFER_SIZE.

Referenced by TWI_SlaveDataHandler().