Atmel Software Framework

common/services/twi/master_example/twi_master_example.c File Reference
#include "board.h"
#include "sysclk.h"
#include "twi_master.h"
#include "led.h"
#include "conf_board.h"

Macros

Local Configuration Constants
#define EEPROM_BUS_ADDR   0x50
 TWI slave bus address. More...
 
#define EEPROM_MEM_ADDR   0xaa
 TWI slave memory address. More...
 
#define TWI_SPEED   50000
 TWI data transfer rate. More...
 

Functions

int main (void)
 TWI Master Example Main. More...
 

Slave EEPROM memory Test Pattern Constants

#define PATTERN_TEST_LENGTH   sizeof(test_pattern)
 
const uint8_t test_pattern []
 

#define EEPROM_BUS_ADDR   0x50

TWI slave bus address.

Referenced by main().

#define EEPROM_MEM_ADDR   0xaa

TWI slave memory address.

Referenced by main().

#define PATTERN_TEST_LENGTH   sizeof(test_pattern)

Referenced by main().

#define TWI_SPEED   50000

TWI data transfer rate.

Referenced by main().

int main ( void  )

TWI Master Example Main.

The master example begins by initializing required board resources. The system clock, basic GPIO pin mapping, and interrupt vectors are established.

A memory location on a TWI slave is written with a fixed test pattern which is then read back into a separate buffer. As a basic sanity check, the original write-buffer values are compared with values read from the slave to a separate buffer. An LED on the development board is illuminated when there is a match between the written and read data.

Returns
Nothing.

The SAM3X_EK, SAM3X Arduino board and SAM4C_EK use two bytes length internal address EEPROM.

References twi_package_t::addr, board_init(), twi_options_t::chip, EEPROM_BUS_ADDR, EEPROM_MEM_ADDR, i, irq_initialize_vectors, length, opt, PATTERN_TEST_LENGTH, twi_options_t::speed, sysclk_init(), test_pattern, twi_master_read(), twi_master_setup(), twi_master_write(), TWI_SPEED, and TWI_SUCCESS.

const uint8_t test_pattern[]
Initial value:
= {
0x55,
0xA5,
0x5A,
0x77,
0x99}

Referenced by main().