Microchip® Advanced Software Framework

mega/drivers/twi/master_example/twi_master_example.c File Reference

TWi master example for megaRF device.

Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.

#include "asf.h"
#include <conf_twi.h>
#include <conf_board.h>

Macros

#define TWI_EXAMPLE   &TWBR
 

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 []
 
const uint8_t slave_mem_addr [SLAVE_MEM_ADDR_LENGTH]
 

#define PATTERN_TEST_LENGTH   sizeof(test_pattern)

Referenced by main().

#define TWI_EXAMPLE   &TWBR

Referenced by main().

int main ( void  )

TWI Master Example Main.

Main function.

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, twi_master_options_t::baud_reg, board_init(), data_received, delay_ms, LED_On, PATTERN_TEST_LENGTH, SLAVE_BUS_ADDR, slave_mem_addr, SLAVE_MEM_ADDR_LENGTH, twi_master_options_t::speed, sysclk_enable_peripheral_clock(), sysclk_get_cpu_hz(), sysclk_init(), test_pattern, TWI_CLOCK_RATE, TWI_EXAMPLE, twi_master_init(), twi_master_read(), twi_master_write(), and TWI_SUCCESS.

const uint8_t slave_mem_addr[SLAVE_MEM_ADDR_LENGTH]
Initial value:
= {
0x00,
}

Referenced by main().

const uint8_t test_pattern[]
Initial value:
= {
0x05,
0x15,
0x25,
0x35,
0x45,
0x55,
0x65,
0x75,
}