4.2.2 Atmel megaAVR with TWI Interface

The following code section contains definitions related to this target.

//******************MEGAAVR TWI PARAMETERS***********************/
#elif defined(MEGAAVR) && defined(TWI) 
    #include "atmega_twi_driver.h" 
    /*! \brief Largest message size that will be sent/received 
    excluding address byte and register address. When using array 
    write/read functions, the count parameter can not exceed 
    NUM_BYTES*/ 
    #define NUM_BYTES 16 
    // Bit rate Register setting for 8MHz CPU clock, 100 KHz SCL 
    #define TWI_TWBR 0x20  
    #define TWI_TWPS 0x00 
//*****************************************************************
  • NUM_BYTES defines the maximum number of data bytes that can be sent in one transfer. It is used when using the array read/write commands. The count parameter can not exceed NUM_BYTES.
  • TWI_BUFFER_SIZE defines the size of TX/RX buffer. In simple read/write transactions with MSL, three bytes are transferred one way.
  • TWI_TWBR and TWI_TWPS define the baud rate register settings according to the equation below. Carefully enter these to set the SCL clock frequency.
S C L = C P U _ C L O C K _ F R E Q 16 + 2 * T W B R * ( 4 T W P S )