/***************************************************************************** * * Atmel Corporation * * File : TWI_Master.c * Compiler : IAR EWAAVR 2.28a/3.10c * Revision : $Revision: 1.13 $ * Date : $Date: 24. mai 2004 11:31:20 $ * Updated by : $Author: ltwa $ * * Support mail : avr@atmel.com * * Supported devices : All devices with a TWI module can be used. * The example is written for the ATmega16 * * AppNote : AVR315 - TWI Master Implementation * * Description : This is a sample driver for the TWI hardware modules. * It is interrupt driveren. All functionality is controlled through * passing information to and from functions. Se main.c for samples * of how to use the driver. * * ****************************************************************************/ #include #include #include "avr_twi_master.h" //static unsigned char TWI_buf[ TWI_BUFFER_SIZE ]; // Transceiver buffer static unsigned char *TWI_buf; static unsigned char TWI_msgSize; // Number of bytes to be transmitted. static unsigned char TWI_sendStop; static unsigned char TWI_state = TWI_NO_STATE; // State byte. Default set to TWI_NO_STATE. union TWI_statusReg TWI_statusReg = {0}; // TWI_statusReg is defined in TWI_Master.h /**************************************************************************** Call this function to set up the TWI master to its initial standby state. Remember to enable interrupts from the main application after initializing the TWI. ****************************************************************************/ void TWI_Master_Initialise(void) { TWBR = TWI_TWBR; // Set bit rate register (Baudrate). Defined in header file. // TWSR = TWI_TWPS; // Not used. Driver presumes prescaler to be 00. TWDR = 0xFF; // Default content = SDA released. TWCR = (1<