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 TWI peripheral in slave mode.

Requirements

This package can be used with SAM evaluation kits.

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 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 0x40. If the board has a TWI 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 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/