Purpose
This basic example program demonstrates how to use the TWI peripheral to access an external serial EEPROM chip.
Requirements
This package can be used with SAM V71 Xplained Ultra board,
Description
The code can be roughly broken down as follows:
-
Configure TWI pins.
-
Enable TWI peripheral clock.
-
Configure TWI clock.
-
Initialize TWI as twi master.
-
TWI interrupt handler.
-
The main function, which implements the program behaviour.
-
Set the first and second page of the EEPROM to all zeroes.
-
Write pattern in page 0.
-
Read back data in page 0 and compare with original pattern (polling).
-
Write pattern in page 1.
-
Read back data in page 1 and compare with original pattern (interrupts).
Usage
- Build the program and download it inside the SAM V71 Xplained Ultra board. Please refer to the Getting Started with SAM V71 Microcontrollers.pdf
On the computer, open and configure a terminal application (e.g. HyperTerminal on Microsoft Windows) with these settings:
- 115200 baud rate
- 8 bits of data
- No parity
- 1 stop bit
- No flow control
Start the application.
- In the terminal window, the following text should appear:
-- TWI EEPROM Example xxx --
-- SAMxxxxx-xx
-- Compiled: xxx xx xxxx xx:xx:xx --
- The following traces detail operations on the EEPROM, displaying success or error messages depending on the results of the commands.
References