-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstm32_sw_i2c.h
50 lines (32 loc) · 1.59 KB
/
stm32_sw_i2c.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
stm32_sw_i2c.h - Library for implementing I2C in SW on any GPIO on STM32 MCU.
Created by Mawaba Pascal Dao, Dec 2, 2020.
Released into the public domain.
*/
#ifndef __STM32_SW_I2C_H
#define __STM32_SW_I2C_H
#include "main.h"
#include "dwt_stm32_delay.h"
#define I2C_CLEAR_SDA HAL_GPIO_WritePin(SW_I2C_SDA_GPIO_Port, SW_I2C_SDA_Pin, GPIO_PIN_RESET);
#define I2C_SET_SDA HAL_GPIO_WritePin(SW_I2C_SDA_GPIO_Port, SW_I2C_SDA_Pin, GPIO_PIN_SET);
//#define I2C_READ_SDA {if (HAL_GPIO_ReadPin(SW_I2C_SDA_GPIO_Port, SW_I2C_SDA_Pin)) == GPIO_PIN_SET) return 1; else return 0; return 0;};
#define I2C_CLEAR_SCL HAL_GPIO_WritePin(SW_I2C_SCL_GPIO_Port, SW_I2C_SCL_Pin, GPIO_PIN_RESET);
#define I2C_SET_SCL HAL_GPIO_WritePin(SW_I2C_SCL_GPIO_Port, SW_I2C_SCL_Pin, GPIO_PIN_SET);
#define I2C_DELAY DWT_Delay_us(5); // 5 microsecond delay
//void I2C_bus_init(uint8_t scl_pin, uint8_t sda_pin, uint8_t port);
void I2C_init(void);
void I2C_start_cond(void);
void I2C_stop_cond(void);
void I2C_write_bit(uint8_t b);
uint8_t I2C_read_SDA(void);
// Reading a bit in I2C:
uint8_t I2C_read_bit(void);
_Bool I2C_write_byte(uint8_t B, _Bool start, _Bool stop);
uint8_t I2C_read_byte(_Bool ack, _Bool stop);
_Bool I2C_send_byte(uint8_t address, uint8_t data);
uint8_t I2C_receive_byte(uint8_t address);
_Bool I2C_send_byte_data(uint8_t address, uint8_t reg, uint8_t data);
uint8_t I2C_receive_byte_data(uint8_t address, uint8_t reg);
_Bool I2C_transmit(uint8_t address, uint8_t data[], uint8_t size);
_Bool I2C_receive(uint8_t address, uint8_t reg[], uint8_t *data, uint8_t reg_size, uint8_t size);
#endif /*__STM32_SW_I2C_H */