From: Michel Pollet Date: Thu, 24 Feb 2011 18:03:24 +0000 (+0000) Subject: twi: Placeholder example board X-Git-Tag: v1.0a7~6 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=13ee4cc59eab9c0972bdea63bee9f74757fc609f;p=sx%2Fsimavr.git twi: Placeholder example board Uses AVR application note implementation of master/slave mode Placeholder, non functional Signed-off-by: Michel Pollet --- diff --git a/examples/board_i2ctest/Makefile b/examples/board_i2ctest/Makefile new file mode 100644 index 0000000..e69de29 diff --git a/examples/board_i2ctest/twi_master.c b/examples/board_i2ctest/twi_master.c new file mode 100644 index 0000000..16c19b9 --- /dev/null +++ b/examples/board_i2ctest/twi_master.c @@ -0,0 +1,216 @@ +/***************************************************************************** +* +* 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 "ioavr.h" +#include "inavr.h" +#include "TWI_Master.h" + +static unsigned char TWI_buf[ TWI_BUFFER_SIZE ]; // Transceiver buffer +static unsigned char TWI_msgSize; // Number of bytes to be transmitted. +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<