How To Use MCU ATtiny1616 To Read Write I2C Devices

How To Use MCU ATtiny1616 To Read Write I2C Devices

Table Of Content

  1. Introduction
  2. Atmel Studio 7 IDE
  3. Atmel START Windows
  4. Select the Device
  5. Create New Project
  6. Select Software Component (I2C)
  7. 7.I2C Driver Configuration
  8. Select I2C Pins
  9. Select I2C Mode
  10. Set I2C Speed
  11. Configure the Main Clock
  12. Generate Project
  13. I2C Initialization Code
  14. Clock Initialization Code
  15. I2C Pin Configuration Code
  16. Complete Code Example
  17. Additional Resources
  18. ?Conclusion

Introduction

Embedded systems have become integral to modern technology, driving innovations in automation, consumer electronics, and industrial applications. At the heart of these systems are microcontrollers (MCUs), which perform critical tasks with precision and efficiency. Among the myriad of MCUs available, the ATtiny1616 from Microchip stands out due to its versatility, low power consumption, and rich set of features tailored for a wide range of applications.

In this article, we delve into the development of Embedded C applications for the ATtiny1616, utilizing Atmel Studio 7—a powerful Integrated Development Environment (IDE) designed specifically for Atmel microcontrollers. Our focus will be on harnessing the capabilities of the Inter-Integrated Circuit (I2C) protocol, a widely used communication standard in embedded systems.

The ATtiny1616, part of the tinyAVR? 1-series, offers a robust and cost-effective solution for embedded developers. It boasts features such as 16 KB of Flash memory, 2 KB of SRAM, and a rich set of peripherals, including multiple I2C interfaces. This makes it an ideal choice for applications requiring efficient data transfer between various components.

We will guide you through the process of setting up an I2C communication system on the ATtiny1616, covering both reading from and writing to I2C devices.

Atmel Studio 7 IDE

Atmel Studio is an Integrated Development Environment (IDE) for writing and debugging AVR

/ARM applications in Windows 7/8/10 environments.

Atmel Studio provides a project management tool, source file editor, simulator, assembler, and front-end for C/C++, programming, and on-chip debugging.

Atmel Studio supports the complete range of Microchip AVR tools.

Open Atmel START Windows

Atmel START is a web-based software configuration tool, for various software frameworks, which helps you get started with MCU development.

Atmel START enables you to:

  • Get help with selecting an MCU, based on both software and hardware requirements.
  • Find and develop examples for your board.
  • Configure drivers, middleware, and example projects.
  • Get help with setting up a valid PINMUX layout.

Select the Device

Use the ‘Filter on device’ text input box to select the device before creating a new project.

?You can filter devices by what software you need and also with hardware requirements such as memory sizes.

Select “ATtiny1616-MFR” MCU

Type ATtiny1616-MFR on the ‘Filter on device’ text input box

Create New Project

In the list of the drivers, select and add at least one instance of the I2C driver.

If the MCU selected has more than one I2C peripheral, then may select more than one instance.

Click on ‘CREATE NEW PROJECT’ to create a new blank project using the selected device.

Select Software Component (I2C_0)

In the dashboard click on the I2C_0 driver box to access the I2C driver configuration options.

I2C Driver Configuration Options

Select I2C Pins

Use the COMPONENT SIGNALS to select the I2C pins.

Select I2C Mode

In the ‘Driver’ text input box select Driver:I2C:Master to make the MCU to be the master I2C device.

In the ‘Mode’ text input box select Interrupt as the method to control the I2C peripheral?

Set I2C Speed

Set the I2C peripheral speed. In this case we set the speed to be 100KHz.

Configure the Main Clock

Click on the clock configurator button (highlighted in red) to show the Clock Configurator screen.

The clock system consists of oscillators and sources of different types. By using the Clock Configurator you can configure each source and oscillator, and see the calculated output frequency.

Click on the Main Clock (CLK_MAIN) box to show the main clock configuration.

Configure the main clock source, enable the prescaler, and set the prescaler value.

These settings can be changed later in the code.

Pinmux Configurator

Click on the highlighted button to show the Pinmux Configurator screen.

The Pinmux Configurator presents an overview of all the configured pins.

Select one or more GPIO pins in the Pin Assignment table (highlighted in red), and the Pin Details Editor will open at the bottom of the screen.

The Pin Details Editor (highlighted in red) is used for setting properties for GPIO pins.

Generate Project

Click on the GENERATE PROJECT button (highlighted in red) to open the Atmel Start Importer screen.

Choose the project location and enter a project name then click OK to generate the project.

When the project generation has finished, the Solution Explorer will pop up showing the project folder and files tree.

Click on any folder or file to show it.

Project Folder and Files Tree

I2C Initialization Code

To change the I2C settings, click on the file i2c_master.c and look for the function I2C_0_init().

Clock Initialization Code

To change the clock settings, click on the file clkctrl.c and look for the function CLKCTRL_init ().

I2C Pin Configuration Code

To change the I2C pins setting, click on driver_init.c and look for the function I2C_0_initialization().

Complete Code Example

Additional Resources

1. Atmel Studio 7 User Guide

https://www.microchip.com/content/dam/mchp/documents/atmel-start/Atmel-Studio-7-User-Guide.pdf

2. Atmel START User's Guide

https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-START-User-Guide-DS50002793A.pdf

3. Atmel START

https://start.atmel.com/

4. Microchip Studio for AVR and SAM Devices- Offline Installer

https://ww1.microchip.com/downloads/aemDocuments/documents/DEV/ProductDocuments/SoftwareTools/as-installer-7.0.2594-full.exe

Conclusion

Developing Embedded C applications for the ATtiny1616 using Atmel Studio 7 offers a powerful and efficient way to harness the capabilities of this versatile microcontroller. By leveraging the I2C protocol, developers can facilitate seamless communication between the ATtiny1616 and various peripheral devices, enabling a wide range of applications from sensor data acquisition to complex control systems.

Throughout this article, we have explored the critical steps required to set up and configure the development environment, initialize the I2C module, and implement both read and write operations. These practical examples and code snippets provide a solid foundation for building robust embedded applications. Additionally, the troubleshooting tips offer valuable insights into diagnosing and resolving common issues encountered during I2C communication.

By mastering these techniques, you can unlock the full potential of ATtiny1616, creating efficient, reliable, and scalable solutions for your embedded projects. Whether you are a seasoned developer or just starting in the world of microcontrollers, the knowledge gained from this guide will empower you to tackle new challenges and innovate with confidence.

要查看或添加评论,请登录

Yamil Garcia的更多文章

社区洞察

其他会员也浏览了