Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
TWIHS Slave Example

Introduction

The application demonstrates how to use use the TWIHS in high speed slave mode.

Requirements

This package can be used with the following setup:

  • SAMG53 Xplained Pro kit
  • SAMV71 Xplained Ultra kit
  • SAME70 Xplained kit

In addition, another device will be needed to act as the TWI master. The twi_eeprom_example can be used for that, in which case a second kit supported by that project is needed.

  1. Connect TWD (SDA) for the 2 boards.
  2. Connect TWCK (SCL) for the 2 boards.
  3. Connect GND for the 2 boards.
  4. Make sure there is a pull up resistor on TWD and TWCK.

Main files:

Description of the Example

After launching the program, the device will act as a simple TWI-enabled serial memory containing 512 bytes. This enables this project to be used with the twi_eeprom_example project as the master.

To write in the memory, the TWIHS master must address the device first, then send two bytes containing the memory address to access. Additional bytes are treated as the data to write.

Reading is done in the same fashion, except that after receiving the memory address, the device will start outputting data until a STOP condition is sent by the master. The default address for the TWIHS slave is fixed to 0x40. If the board has a TWIHS component with this address, you can change the define AT24C_ADDRESS in twi_eeprom_example.c of twi_eeprom_example project, and the define SLAVE_ADDRESS in twihs_slave_example.c of twihs_slave_exmaple project.

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/