HWA
Bare metal programming with style
Class _twia: 2-wire interface

This class is used by:

Interrupts

Class _twia objects can trigger the following IRQs:

Actions

hw( configure, TWI, ... ) and hwa( configure, TWI, ... ) configure the TWI:

hw | hwa( configure, twi0,
[ bps, <value>, ] // SCL speed
[ slave_address, <value>, ]
[ general_call, enabled
| disabled, ]
[ slave_address_mask, <value> ] );
Note
The TWI does not take control of the SCL and SDA pins until a xfr_ action is triggered. Then, it keeps control over these pins until the TWI is disabled.


turn:

hw( turn, twi0, on | off );
hwa( turn, twi0, on | off );
hw( xfr_start, twi0 [,irq] ); // Transmit START condition
hw( xfr_slaw, twi0, SLA [,irq] ); // Transmit SLA slave address + write bit
hw( xfr_slar, twi0, SLA [,irq] ); // Transmit SLA slave address + read bit
hw( xfr_write, twi0, DATA [,irq] ); // Transmit DATA
hw( xfr_read, twi0, ack | nack [,irq] ); // Receive one byte, send ACK or NACK
hw( xfr_stop, twi0 [,irq] ); // Transmit STOP condition

The optionnal irq parameter can be used to have the command enable the IRQ.

These actions set the 'TWEN' bit so that the TWI takes control of the I/O pins.

read:

uint8_t byte = hw( read, twi0 );


stat: returns the status flags of the TWI as a byte whose value can be compared to HWA predefined symbols:

if ( hw(stat,twi0) == HW_TWI_START ) {
// Start condition has been transmitted
}

Predefined TWI status symbols are:

Registers

Class _twia objects hold the following hardware registers:

that hold the following logical registers:

hwa
#define hwa(...)
hwa( action, object [,...] ) stores an action for an object into a HWA context.
Definition: hwa_macros.h:552
hw
#define hw(...)
hw( action, object [,...] ) executes an action immediately on an object.
Definition: hwa_macros.h:523