X-Git-Url: http://git.smho.de/gw/?p=owSlave2.git;a=blobdiff_plain;f=common%2FI2C%2FUSI_TWI_Master.c;fp=common%2FI2C%2FUSI_TWI_Master.c;h=d5f259640b75d75a724a39e6fd0f741b3fb04281;hp=5e6dea85656c347b98042b604d1ef171f35e3925;hb=a6a04f58e4afd20f206fdf4a8a7b3ce4062f1b67;hpb=cd92472e6fd63693741f8e168123a4182802651b diff --git a/common/I2C/USI_TWI_Master.c b/common/I2C/USI_TWI_Master.c index 5e6dea8..d5f2596 100644 --- a/common/I2C/USI_TWI_Master.c +++ b/common/I2C/USI_TWI_Master.c @@ -1,322 +1,322 @@ -/***************************************************************************** -* -* Atmel Corporation -* -* File : USI_TWI_Master.c -* Compiler : AVRGCC Toolchain version 3.4.2 -* Revision : $Revision: 992 $ -* Date : $Date: 2013-11-07 $ -* Updated by : $Author: Atmel $ -* -* Support mail : avr@atmel.com -* -* Supported devices : All device with USI module can be used. -* The example is written for the ATmega169, ATtiny26 and ATtiny2313 -* -* AppNote : AVR310 - Using the USI module as a TWI Master -* -* Description : This is an implementation of an TWI master using -* the USI module as basis. The implementation assumes the AVR to -* be the only TWI master in the system and can therefore not be -* used in a multi-master system. -* Usage : Initialize the USI module by calling the USI_TWI_Master_Initialise() -* function. Hence messages/data are transceived on the bus using -* the USI_TWI_Transceive() function. The transceive function -* returns a status byte, which can be used to evaluate the -* success of the transmission. -* -****************************************************************************/ -#define F_CPU 8000000UL -#include -#include "USI_TWI_Master.h" -#include - -unsigned char USI_TWI_Master_Transfer( unsigned char ); -unsigned char USI_TWI_Master_Stop( void ); - -union USI_TWI_state -{ - unsigned char errorState; // Can reuse the TWI_state for error states due to that it will not be need if there exists an error. - struct - { - unsigned char addressMode : 1; - unsigned char masterWriteDataMode : 1; - unsigned char unused : 6; - }; -} USI_TWI_state; - -/*--------------------------------------------------------------- - USI TWI single master initialization function ----------------------------------------------------------------*/ -void USI_TWI_Master_Initialise( void ) -{ - PORT_USI |= (1< (unsigned char*)RAMEND) // Test if address is outside SRAM space - { - USI_TWI_state.errorState = USI_TWI_DATA_OUT_OF_BOUND; - return (FALSE); - } - if(msgSize <= 1) // Test if the transmission buffer is empty - { - USI_TWI_state.errorState = USI_TWI_NO_DATA; - return (FALSE); - } -#endif - -#ifdef NOISE_TESTING // Test if any unexpected conditions have arrived prior to this execution. - if( USISR & (1< +#include "USI_TWI_Master.h" +#include + +unsigned char USI_TWI_Master_Transfer( unsigned char ); +unsigned char USI_TWI_Master_Stop( void ); + +union USI_TWI_state +{ + unsigned char errorState; // Can reuse the TWI_state for error states due to that it will not be need if there exists an error. + struct + { + unsigned char addressMode : 1; + unsigned char masterWriteDataMode : 1; + unsigned char unused : 6; + }; +} USI_TWI_state; + +/*--------------------------------------------------------------- + USI TWI single master initialization function +---------------------------------------------------------------*/ +void USI_TWI_Master_Initialise( void ) +{ + PORT_USI |= (1< (unsigned char*)RAMEND) // Test if address is outside SRAM space + { + USI_TWI_state.errorState = USI_TWI_DATA_OUT_OF_BOUND; + return (FALSE); + } + if(msgSize <= 1) // Test if the transmission buffer is empty + { + USI_TWI_state.errorState = USI_TWI_NO_DATA; + return (FALSE); + } +#endif + +#ifdef NOISE_TESTING // Test if any unexpected conditions have arrived prior to this execution. + if( USISR & (1<