Microchip® Advanced Software Framework

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

Introduction

The application demonstrates how to use use the SAM TWIS peripheral.

Requirements

This package can be used with SAM4L boards.

In addition, another device will be needed to act as the TWI master. The twim_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. Add a pull up resistor on TWD and TWCK

Main files:

  • twis.c SAM Two-Wire Slave Interface driver implementation.
  • twis.h SAM Two-Wire Slave Interface driver definitions.
  • twi_slave_example.c Example application.

Description of the Example

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

To write in the memory, the TWI 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 TWI slave is fixed to 0x50. If the board has a TWI component with this address, you can change the define TARGET_ADDRESS in conf_example.h of twim_example project, and the define SLAVE_ADDRESS in twi_slave_example.c of twi_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/