This project is to have a simple example of a controller I2C communication on an ATtiny85 with documentation.
Supports writing and reading from target devices.
src
The main source code foldersrc/main.c
The main file for using the I2C driver.src/driver/i2c.[h|c]
The I2C driver implementation files.install_deps.sh
Run this to install all the tools needed to build and flash AVR projects.Makefile
Contains commands to build and burn the AVR project.compile_flags.txt
Contains setup flags to work with the C LSP (clangd)
The demo has an ATtiny85 loaded with the code in this project hooked up to an arduino uno using the Wire library to act as a target device to talk to.
Actions performed:
- The controller (ATtiny85) sends "Hello, World!" to the target (Arduino Uno) device.
- The controller requests a read from the target to toggle the LED.
i2c-avr-coms.mp4
If using USBTiny programmer on linux you may have to run the upload command with sudo because of permission issues.
Another gotcha with the USBTiny is if it has an LED on the SDA pin it will mess with your data line. So don't use the USBTiny programmer to test your ATtiny85.
If you are trying to develop in WSL you need to forward the USB device onto the WSL environment.
-
Start by downloading this utility program
winget install --interactive --exact dorssel.usbipd-win
-
Look for the USB port the arduino is using.
$ usbipd list
- Bind the USB port
$ usbipd bind --busid <port> # example would be 1-2
- Attach to WSL environment
$ usbipd attach --wsl --busid <port>
- Verify the USB port on WSL.
If you do not have lsusb find whatever your system uses.
This will list the USB ports you have access to and the arduino port should be in the list.
$ lsusb
Once done you can just detach the USB port.