Skip to content

Commit

Permalink
Merge pull request #8 from akkoyun/01.03.02
Browse files Browse the repository at this point in the history
01.03.02 - Readme update
  • Loading branch information
akkoyun authored Feb 25, 2022
2 parents 722ef4c + 3344588 commit 19a5821
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 4 deletions.
142 changes: 140 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,140 @@
# I2C_Functions
Generic I2C Functions.
# I2C Functions Library <sup>V1.3</sup>

![GitHub release (latest by date)](https://img.shields.io/github/v/release/akkoyun/I2C_Functions) ![arduino-library-badge](https://www.ardu-badge.com/badge/I2C_Functions.svg?) ![Visits Badge](https://badges.pufler.dev/visits/akkoyun/I2C_Functions) ![GitHub stars](https://img.shields.io/github/stars/akkoyun/I2C_Functions?style=flat&logo=github) ![Updated Badge](https://badges.pufler.dev/updated/akkoyun/I2C_Functions) ![PlatformIO Registry](https://badges.registry.platformio.org/packages/akkoyun/library/I2C_Functions.svg)

Build - 01.03.02

---

##### Abstract

This is a helper library to abstract away I2C transactions and registers.

Library includes some helper I2C functions and a generic I2C multiplexer function.

* Control_Device
* Read_Register
* Read_Multiple_Register
* Write_Register
* Write_Multiple_Register
* Write_Command
* Set_Register_Bit
* Clear_Register_Bit
* Read_Register_Bit
* Set_Multiplexer

##### I2C Device Control

Library can control the I2C device and if connected function returns ```true```

```C++
bool Sensor_Connected = I2C.Control_Device(0x40);
```

##### I2C Read Single Register

Library can read a single register on I2C device and function returns readed register from device in ```uint8_t``` format

```C++
uint8_t Register = I2C.Read_Register(0x40, 0x01);
```

##### I2C Write Single Register

Library can write a single byte of data to specified register on the selected I2C device. Function also allows the end connection parameter. Function returns success response if command is success.

```C++
uint8_t I2C_Address = 0x40;
uint8_t Register = 0x01;
uint8_t Data = 0x00;

bool Success = Write_Register(I2C_Address, Register, Data, false);
```

##### I2C Write Command

Library can write a single command to the selected I2C device. Function also allows the end connection parameter. Function returns success response if command is success.

```C++
uint8_t I2C_Address = 0x40;
uint8_t Command = 0x01;

bool Success = Write_Command(I2C_Address, Command, false);
```

##### I2C Read Multiple Register Command

Library can read multiple register from the selected I2C device. Readed data stores in the out function array. Function also allows the end connection parameter. Function returns success response if command is success.

```C++
uint8_t I2C_Address = 0x40;
uint8_t Register = 0x01;
uint8_t Data[2];
uint8_t Length = 2;

bool Success = Read_Multiple_Register(I2C_Address, Register, Data, Length, false);
```

##### I2C Write Multiple Register Command

Library can write multiple register to the selected I2C device. Sended data stores in the out function array. Function also allows the end connection parameter. Function returns success response if command is success.

```C++
uint8_t I2C_Address = 0x40;
uint8_t Register = 0x01;
uint8_t Data[2] = {0x01, 0x04};
uint8_t Length = 2;

bool Success = Write_Multiple_Register(I2C_Address, Register, Data, Length);
```
##### I2C Set Register Bit Command
In some conditions we need to change a bit on register and write again to device. This library can do it on single function. You can specify address, register and selected bit. Function also allows the end connection parameter. Function returns success response if command is success.
```C++
uint8_t I2C_Address = 0x40;
uint8_t Register = 0x01;
uint8_t Bit_Number = 2;
bool Success = Set_Register_Bit(I2C_Address, Register, Bit_Number, false);
```

##### I2C Clear Register Bit Command

In some conditions we need to change a bit on register and write again to device. This library can do it on single function. You can specify address, register and selected bit. Function also allows the end connection parameter. Function returns success response if command is success.

```C++
uint8_t I2C_Address = 0x40;
uint8_t Register = 0x01;
uint8_t Bit_Number = 2;

bool Success = Clear_Register_Bit(I2C_Address, Register, Bit_Number, false);
```

##### I2C Read Register Bit Command

In some conditions we need to read a bit on register. This library can do it on single function. You can specify address, register and selected bit. Function also allows the end connection parameter. Function returns success response if command is success.

```C++
uint8_t I2C_Address = 0x40;
uint8_t Register = 0x01;
uint8_t Bit_Number = 2;

bool Success = Read_Register_Bit(I2C_Address, Register, Bit_Number, false);
```

##### I2C Generic Multiplexer Command

If your I2C structure contains a I2C Multiplexer, you need to use a aditional library (or command set). In this library you can also use a generic multiplexer channel set command. Function returns success response if command is success.

```C++
uint8_t I2C_Address = 0x40;
uint8_t Channel = 0x01;

bool Success = Set_Multiplexer(I2C_Address, Channel);
```

---

[![Support me](https://img.shields.io/badge/Support-PATREON-GREEN.svg)](https://www.patreon.com/bePatron?u=62967889) ![Twitter Follow](https://img.shields.io/twitter/follow/gunceakkoyun?style=social) ![YouTube Channel Views](https://img.shields.io/youtube/channel/views/UCIguQGdaBT1GnnVMz5qAZ2Q?style=social) ![Repos Badge](https://badges.pufler.dev/repos/akkoyun) [![E-Mail](https://img.shields.io/badge/E_Mail-Mehmet_Gunce_Akkoyun-blue.svg)](mailto:[email protected]) ![GitHub](https://img.shields.io/github/license/akkoyun/Statistical)
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "I2C_Functions",
"version": "1.3.1",
"version": "1.3.2",
"keywords": "I2C, Sensor, Data, Communication, Multiplexer, Detect, Register, Functions",
"description": "Generic I2C data communication standard functions.",
"authors": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=I2C_Functions
version=1.3.1
version=1.3.2
author=Gunce Akkoyun <[email protected]>
maintainer=Gunce Akkoyun <[email protected]>
sentence=Generic I2C data communication standard functions.
Expand Down
8 changes: 8 additions & 0 deletions src/I2C_Sensor_Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define __ADDR_HDC201__ (uint8_t)0x40
#define __ADDR_MAX17055__ (uint8_t)0x36
#define __ADDR_BQ24298__ (uint8_t)0x6B
#define __ADDR_SHT21__ (uint8_t)0x40

enum Multiplexer_Channels {
__OFF__ = 0,
Expand All @@ -21,4 +22,11 @@ enum Multiplexer_Channels {
__CH8__ = 8
};

enum SHT21_Registers {
__SHT21_SOFT_RESET_ = 0xFE,
__SHT21_USER_REGISTER_ = 0xE6,
__SHT21_T_MEASUREMENT_ = 0xE3,
__SHT21_H_MEASUREMENT_ = 0xE5,
};

#endif

0 comments on commit 19a5821

Please sign in to comment.