Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
TWI MASTER Example

Introduction

The application demonstrates how to use the SAM TWIHS driver to access an external serial EEPROM chip.

Requirements

This package can be used with the following setup:

  • SAMV71 Xplained Ultra kit
  • SAME70 Xplained kit

Main files:

  • twihs.c SAM Two-Wire Interface driver implementation.
  • twihs.h SAM Two-Wire Interface driver definitions.
  • TWIHS_master_example.c Example application.

Description of the Example

Upon startup, the program configures PIOs for console UART, LEDs and TWIHS connected to EEPROM on board. Then it configures the TWIHS driver and data package. The clock of I2C bus is set as 400kHz. After initializing the master mode, the example sends test pattern to the EEPROM. When sending is complete, TWIHS driver reads the memory and saves the content in the reception buffer. Then the program compares the content received with the test pattern sent before and prints the comparison result. The corresponding LED is turned on.

On SAM Xplained Pro, the EEPROM is simulated though the TWIHS_slave_example, which means 2 SAM Xplained Pro boards are required to run this example. One board executes this example as the twi master and another runs TWIHS_salve_example as the simulated EEPROM. The TWI PINs and GND PIN should be connected between these 2 boards. More information of the simulated EEPROM implementation can be referred in the description of TWIHS_slave_example.

Compilation Info

This software was written for the GNU GCC and IAR EWARM. Other compilers may or may not work.

Contact Information

For further information, visit Microchip.
Support and FAQ: https://www.microchip.com/support/