This driver is the implementation of TWI module of megaRF device as slave.
Master initiates and terminates a data transmission.In the Slave Transmitter mode, a number of data bytes are transmitted to a Master. In the Slave Receiver mode, a number of data bytes are received from a Master. This uses two bi-directional bus lines(PD0 and PD1), one to receive clock (SCL) from master and one for data (SDA)
Configuration is done in the configuration file : conf_twi.h
Configuration defines:
The twi module should be configured as slave. The slave address is set in TWAR register. The upper 7 bits are the address to which the 2-wire Serial Interface will respond when addressed by a Master. If the LSB is set(TWI_GCE), the TWI will respond to the general call address (0x00), otherwise it will ignore the general call address. Enabling of TWI as slave is done by calling the function:
The include file needed is:
After initiating the twi as slave,the TWI waits until it is addressed by its own slave address (or the general call address if enabled) followed by the data direction bit. If the direction bit is (read), the TWI will operate in Slave transmit mode, otherwise Slave receive mode is entered
The status and state is indicated to the application code through the following functions
Functions | |
static void | twi_slave_bus_reset (void) |
Reset TWI bus. More... | |
static void | twi_slave_data_read (uint8_t data) |
Read received data. More... | |
static void | twi_slave_data_write (void) |
Sending data to twi bus. More... | |
static void | twi_slave_enable (void) |
Enable TWI as slave. More... | |
status_code_t | twi_slave_init (uint8_t twi_slave_ownadd) |
Initialize TWI as Slave. More... | |
static void | twi_slave_last_byte_write_done (void) |
Notification of Last byte is transmitted. More... | |
status_code_t | twi_slave_start (slave_data_buffer_t *package) |
Start the slave Transceiver. More... | |
int | twi_slave_state_get (void) |
Get the state of TWI transceiver. More... | |
int | twi_slave_status_get (void) |
Get the status of TWI transceiver. More... | |
void | twi_slave_status_reset (void) |
Resets the slave state and status to initial for next transmission/reception. More... | |
static void | twi_slave_write_byte (uint8_t data) |
writing an byte to TWI. More... | |
|
static |
Reset TWI bus.
none. |
References slave_transfer, TWI_IDLE, and twi_reset().
Referenced by twi_interrupt_handler().
|
static |
Read received data.
data | - Contains data read from twi bus to be written to data receive buffer. |
References data, slave_transfer, and twi_slave_enable().
Referenced by twi_interrupt_handler().
|
static |
Sending data to twi bus.
none. |
References slave_transfer, and twi_slave_write_byte().
Referenced by twi_interrupt_handler().
|
inlinestatic |
Enable TWI as slave.
none. |
Referenced by twi_interrupt_handler(), twi_slave_data_read(), twi_slave_last_byte_write_done(), twi_slave_status_reset(), and twi_slave_write_byte().
status_code_t twi_slave_init | ( | uint8_t | twi_slave_ownadd | ) |
Initialize TWI as Slave.
TWI_ownAddress | - contains Slave own Address |
References slave_transfer, STATUS_OK, TWI_IDLE, and TWI_STATUS_NO_STATE.
Referenced by main(), and twi_slave_setup().
|
static |
Notification of Last byte is transmitted.
none. |
References slave_transfer, TWI_IDLE, twi_slave_enable(), and TWI_STATUS_TX_COMPLETE.
Referenced by twi_interrupt_handler().
status_code_t twi_slave_start | ( | slave_data_buffer_t * | package | ) |
Start the slave Transceiver.
References OPERATION_IN_PROGRESS, slave_transfer, STATUS_OK, TWI_IDLE, and twi_slave_status_reset().
Referenced by main().
int twi_slave_state_get | ( | void | ) |
Get the state of TWI transceiver.
References slave_transfer.
Referenced by main().
int twi_slave_status_get | ( | void | ) |
Get the status of TWI transceiver.
Get the Status of TWI transceiver.
References slave_transfer.
Referenced by main().
void twi_slave_status_reset | ( | void | ) |
Resets the slave state and status to initial for next transmission/reception.
References SLAVE, slave_transfer, TWI_IDLE, twi_mode, twi_slave_enable(), and TWI_STATUS_NO_STATE.
Referenced by twi_Receive_Success(), twi_slave_start(), twi_Transmission_Failure(), and twi_Transmit_Success().
|
inlinestatic |
writing an byte to TWI.
data | - contains the data to transmitted ro master. |
References data, and twi_slave_enable().
Referenced by twi_slave_data_write().