CH32 Microcontroller Tutorial Part 6: I2C Communication
0:00 Introduction: This tutorial covers I2C (or IΒ²C) communication on CH32 microcontrollers, building on previous tutorials about GPIOs, USART, timers, PWM, ADC, DMA, and interrupts.
0:49 I2C Basics: I2C uses two lines: SDA (serial data) and SCL (serial clock). Communication is master-slave, with the microcontroller as the master and multiple I2C devices as slaves, each with a unique address.
1:13 Demonstration Devices: The tutorial demonstrates I2C communication using two devices: a PCF8574 GPIO expander and an AS5600 magnetic encoder.
3:39 I2C Initialization: The code initializes the I2C peripheral, including enabling clocks for GPIO and I2C, configuring GPIO pins for SDA and SCL in open-drain mode with alternate function, setting the I2C mode, duty cycle, acknowledgement, address type, and starting the peripheral.
13:04 Send Byte Function: A custom send_byte function is implemented to transmit data to an I2C slave device, handling bus busy status, start condition generation, slave selection, data transfer direction, acknowledgement, and stop condition generation.
18:57 Receive Byte Function: A custom receive_byte function is implemented to receive data from an I2C slave device, similar to the send_byte function but with the receiver direction specified.
21:44 GPIO Expander Control: The tutorial demonstrates controlling the PCF8574 GPIO expander by toggling LEDs connected to its output pins based on characters received via USART. This highlights the open-drain nature of the expander's outputs and their limited current sourcing capability.
33:40 AS5600 Magnetic Encoder: The tutorial demonstrates reading the raw angle from an AS5600 magnetic encoder, combining the high and low bytes from the encoder's registers to obtain a 12-bit angle value.
41:01 Angle Conversion: The code converts the raw 12-bit angle value from the AS5600 to degrees and prints it on the serial terminal, showcasing the encoder's high resolution and ability to detect fine angular displacements.
46:59 Further Resources: The tutorial encourages viewers to visit the website for detailed code examples, calculations, demonstrations, and information about parts and tools used in the video.
50:07 Support and Membership: The tutorial suggests supporting the channel by using affiliate links for purchasing products and by considering a channel membership.