4.1 Selecting the Device and Interface

There are four definitions related to device and interface. Select the target AVR and interface with the first two #defines.

//***************************************************************/
//User can define the device here: ATXMEGA, MEGAAVR or TINYAVR
#define ATXMEGA
//****************************************************************/
//Define the interface here SPI, TWI or SPI_USI
#define TWI

This example shows the target as ATxmega with TWI interface.

‘ATXMEGA’, ‘MEGAAVR’, ‘TINYAVR’, ‘SPI’, ‘TWI’ and ‘SPI_USI’ are essential keywords; do not be use them anywhere else in the code. They selectively compile only the required source files.

The next two defines are shown below.

//CPU Clock on which AVR is running at. It is used to calculate 
//baud rate settings and delays.
#define F_CPU 20000000
//*****************************************************************
//Define slave addresses here. 
#define SLAVE_ADDRESS 0xA0
  • F_CPU is the frequency in Hertz (Hz) at which the AVR is running. It calculates delays and baud rate settings.
  • SLAVE_ADDRESS is the address of the slave MSL. It can be TWI slave or SPI slave. This is a seven bit address and the bit 0 is ignored. Bit 0 is used to indicate a read or a write operation.