1 /* This file has been prepared for Doxygen automatic documentation generation.*/
\r
2 /*! \file *********************************************************************
\r
5 * Headerfile for USI.c
\r
7 * Contains definitions of which I/O-register and pins to use,
\r
8 * communication states, and a declaration of the SPI status struct.
\r
10 * \par Application note:
\r
11 * AVR458: Charging Li-Ion Batteries with BC100
\r
13 * \par Documentation:
\r
14 * For comprehensive code documentation, supported compilers, compiler
\r
15 * settings and supported devices see readme.html
\r
18 * Atmel Corporation: http://www.atmel.com \n
\r
19 * Support email: avr@atmel.com \n
\r
24 * $URL: http://svn.norway.atmel.com/AppsAVR8/avr458_Charging_Li-Ion_Batteries_with_BC100/tag/20070904_release_1.0/code/IAR/USI.h $
\r
25 * $Date: 2007-08-10 09:28:35 +0200 (fr, 10 aug 2007) $\n
\r
26 ******************************************************************************/
\r
31 //******************************************************************************
\r
32 // USI port and pin definitions
\r
33 //******************************************************************************
\r
34 #define USI_OUT_REG PORTB //!< USI port output register.
\r
35 #define USI_IN_REG PINB //!< USI port input register.
\r
36 #define USI_DIR_REG DDRB //!< USI port direction register.
\r
37 #define USI_CLOCK_PIN PB2 //!< USI clock I/O pin.
\r
38 #define USI_DATAIN_PIN PB0 //!< USI data input pin.
\r
39 #define USI_DATAOUT_PIN PB1 //!< USI data output pin.
\r
42 //******************************************************************************
\r
44 //******************************************************************************
\r
46 ST_CMD = 1, //!< USI/SPI command state.
\r
47 ST_ADDR, //!< USI/SPI address state.
\r
48 ST_DATA //!< USI/SPI data state.
\r
52 //******************************************************************************
\r
53 // Struct declarations
\r
54 //******************************************************************************
\r
55 //! \brief Holds SPI status and data
\r
56 struct SPI_Status_struct
\r
58 unsigned char Data : 8; //!< The last received byte.
\r
59 unsigned char Address : 8; //!< Specifies variable to read/write.
\r
60 unsigned char Count : 6; //!< The number of bytes to read/write.
\r
61 unsigned char State : 2; //!< \brief Communication state.
\r
62 //!< \note The states are enumerated in USI.h.
\r
65 //! Master wants to read or write? (TRUE/FALSE)
\r
66 unsigned char Read : 1;
\r
68 //! Read/write from/to EEPROM? (TRUE/FALSE)
\r
69 unsigned char EEPROM : 1;
\r
71 //! Used by SPI_Put() to determine if last byte was transferred.(TRUE/FALSE)
\r
72 unsigned char XferComplete : 1;
\r
74 //! Set if SPI_Put() is called before last byte was transferred.(TRUE/FALSE)
\r
75 unsigned char WriteCollision : 1;
\r
77 typedef struct SPI_Status_struct SPI_Status_t; //!< For convenience.
\r
80 //******************************************************************************
\r
81 // Function prototypes
\r
82 //******************************************************************************
\r
83 void SPI_Init(unsigned char spi_mode);
\r
84 unsigned char SPI_Put(unsigned char val);
\r
85 unsigned char SPI_Get(void);
\r
86 void SPI_Wait(void);
\r