Kendryte K210 uses GPIO to simulate i2c waveform

The i2c that comes with the K210 has a downside. When you read the data, if there is no communication due to the address problem, there is no way to test whether the device is responding through the oscilloscope. If you only send it once, if you don’t respond. The program will be stuck, so sometimes you still need to use the simulated i2c to test, but the simulated i2c also has a disadvantage that the speed is relatively slow, if there are relatively few registers, it is OK, but if there are more, it is not ruled out. There is a risk of error.

Sort out the relevant code, as follows. Here I found a device to make this example code. The code is similar, but you can change it according to your needs. The code is not concise enough, please forgive me:

#ifndef _I2C_GM7122_H
#define _I2C_GM7122_H

#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <FreeRTOS.h>
#include <task.h>

#define GM7122_SLAVE_ADDRESS   0x44


void GM7122_i2c_master_init(void);
uint8_t GM7122_i2c_write_reg(uint8_t reg, uint8_t *data_buf, size_t length);
uint8_t GM7122_i2c_read_reg(uint8_t reg, uint8_t *data_buf, size_t length);
uint8_t GM7122_init(void);
#endif
#include <devices.h>
#include <sys/unistd.h>
#include "i2c_GM7122.h"

#define DELAY_TIME  10
static handle_t piohs;
static ha

Guess you like

Origin blog.csdn.net/smile_5me/article/details/107979483