Microchip® Advanced Software Framework

twi_master_example.c File Reference
#include "board.h"
#include "sysclk.h"
#include "twi_master.h"
#include "led.h"
#include "conf_board.h"


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...


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

Slave EEPROM memory Test Pattern Constants

#define PATTERN_TEST_LENGTH   sizeof(test_pattern)
 Number of test bytes. More...
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)

Number of test bytes.

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.


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

References board_init(), EEPROM_BUS_ADDR, EEPROM_MEM_ADDR, i, irq_initialize_vectors, length, PATTERN_TEST_LENGTH, sysclk_init(), test_pattern, twi_master_read(), twi_master_setup(), twi_master_write(), twi_package_t, TWI_SPEED, and TWI_SUCCESS.

const uint8_t test_pattern[]
Initial value:
= {

Referenced by main().