1.8 I2C Driver Synchronous - I2C Multi Client
This example application demonstrates the multi-client feature of the synchronous mode of the I2C driver by communicating with an external EEPROM and a temperature sensor.
Description
This example uses the I2C driver in synchronous mode and demonstrates the multi-client feature. The application uses a IO1 Xplained Pro Extension Kit that has a temperature sensor and an EEPROM, both interfaced on the same I2C bus.
Two application threads are created which act as clients to the same instance of the I2C driver:
APP_I2C_TEMP_SENSOR_Tasks:
This task remains in blocked state for 1 second. Once unblocked, it reads the temperature from the temperature sensor and posts a semaphore thereby unblocking the second (EEPROM) thread.
APP_I2C_EEPROM_Tasks:
This task remains blocked on a semaphore until a new temperature data is available. Once unblocked, it writes the temperature data to the EEPROM. It also reads and prints the last five saved temperature values from the EEPROM when user inputs a key on the console.
Downloading and Building the Application
To clone or download this application from Github, go to the main page of this repository and then click Clone button to clone this repository or download as zip file. This content can also be downloaded using content manager by following these instructions.
Path of the application within the repository is apps/driver/i2c/sync/i2c_multi_slave/firmware.
To build the application, refer to the following table and open the project using its IDE.
Project Name | Description |
---|---|
sam_g55_xpro_freertos.X | MPLABX project for SAM G55 Xplained Pro Evaluation Kit |
Setting Up the Hardware
The following table shows the target hardware for the application projects.
Project Name | Description |
---|---|
sam_g55_xpro_freertos.X | SAM G55 Xplained Pro Evaluation Kit |
Setting Up SAM G55 Xplained Pro Evaluation Kit
- To run the demo, the following additional hardware are required:
- The A2 address line of TWI must be soldered to GND. This is done to modify the address of the EEPROM on IO1 Xplained Pro Extension Kit. The modification changes the address of the temperature sensor to 0x4B and the EEPROM to 0x53
- Connect the IO1 Xplained Pro Extension Kit to the EXT1 header of the SAM G55 Xplained Pro Evaluation Kit
- Connect the Debug USB port on the board to the computer using a micro USB cable
Running the Application
- Open the Terminal application (Ex.:Tera term) on the computer. Configure the
DEBUG port settings as follows:
- Baud : 115200
- Data : 8 Bits
- Parity : None
- Stop : 1 Bit
- Flow Control : None
- Build and program the application using its IDE.
- Observe the temperature values getting printed on the terminal application every 1 second and temperature value written into EEPROM notification as shown below:
- Press any key on the terminal, last 5 temperature values will be read from the EEPROM and displayed as shown below.