2019-05-02 14:29:39 +09:00
|
|
|
# I2C
|
2019-05-02 14:04:24 +09:00
|
|
|
|
|
|
|
|
This is a class to control M5Stack's Grove-A port (I2C).
|
|
|
|
|
I2C communication needs to be initialized in advance by M5.Begin().
|
|
|
|
|
|
|
|
|
|
## writeCommand()
|
|
|
|
|
|
|
|
|
|
**Syntax:**
|
2020-11-05 11:39:06 +08:00
|
|
|
`bool writeCommand(uint8_t address, uint8_t subAddress);`
|
2019-05-02 14:04:24 +09:00
|
|
|
|
|
|
|
|
**Description:**
|
|
|
|
|
|
|
|
|
|
Write to the specified address.
|
|
|
|
|
Used when there are no parameters.
|
|
|
|
|
|
|
|
|
|
**Function argument**
|
2019-05-02 14:24:19 +09:00
|
|
|
|
2019-05-02 14:04:24 +09:00
|
|
|
| Function argument |Type |Description |
|
|
|
|
|
| --- | --- | --- |
|
|
|
|
|
| address | <code>uint8_t</code> |Slave Address |
|
|
|
|
|
| subAddress | <code>uint8_t</code> |function address |
|
|
|
|
|
|
|
|
|
|
**Function return value**
|
2019-05-02 14:24:19 +09:00
|
|
|
|
2019-05-02 14:04:24 +09:00
|
|
|
| Value |Description |
|
|
|
|
|
| --- | --- |
|
|
|
|
|
|true|Write success|
|
|
|
|
|
|false|Write failure|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## writeByte()
|
|
|
|
|
|
|
|
|
|
**Syntax:**
|
2020-11-05 11:39:06 +08:00
|
|
|
`bool writeByte(uint8_t address, uint8_t subAddress, uint8_t data);`
|
2019-05-02 14:04:24 +09:00
|
|
|
|
|
|
|
|
**Description:**
|
|
|
|
|
|
|
|
|
|
Write to the specified address.
|
|
|
|
|
Used when there is one parameter.
|
|
|
|
|
|
|
|
|
|
**Function argument**
|
2019-05-02 14:24:19 +09:00
|
|
|
|
2019-05-02 14:04:24 +09:00
|
|
|
| Function argument |Type |Description |
|
|
|
|
|
| --- | --- | --- |
|
|
|
|
|
| address | <code>uint8_t</code> |Slave Address |
|
|
|
|
|
| subAddress | <code>uint8_t</code> |function address |
|
|
|
|
|
| data | <code>uint8_t</code> |parameter |
|
|
|
|
|
|
|
|
|
|
**Function return value**
|
2019-05-02 14:24:19 +09:00
|
|
|
|
2019-05-02 14:04:24 +09:00
|
|
|
| Value |Description |
|
|
|
|
|
| --- | --- |
|
|
|
|
|
|true|Write success|
|
|
|
|
|
|false|Write failure|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## writeBytes()
|
|
|
|
|
|
|
|
|
|
**Syntax:**
|
2020-11-05 11:39:06 +08:00
|
|
|
` bool writeBytes(uint8_t address, uint8_t subAddress, uint8_t *data,uint8_t length);`
|
2019-05-02 14:04:24 +09:00
|
|
|
|
|
|
|
|
**Description:**
|
|
|
|
|
|
|
|
|
|
Write to the specified address.
|
|
|
|
|
Use when there are multiple parameters.
|
|
|
|
|
|
|
|
|
|
**Function argument**
|
2019-05-02 14:24:19 +09:00
|
|
|
|
2019-05-02 14:04:24 +09:00
|
|
|
| Function argument |Type |Description |
|
|
|
|
|
| --- | --- | --- |
|
|
|
|
|
| address | <code>uint8_t</code> |Slave Address |
|
|
|
|
|
| subAddress | <code>uint8_t</code> |function address |
|
|
|
|
|
| data | <code>uint8_t *</code> | top of data memory |
|
|
|
|
|
| length | <code>uint8_t</code> | length of data |
|
|
|
|
|
|
|
|
|
|
**Function return value**
|
2019-05-02 14:24:19 +09:00
|
|
|
|
2019-05-02 14:04:24 +09:00
|
|
|
| Value |Description |
|
|
|
|
|
| --- | --- |
|
|
|
|
|
|true|Write success|
|
|
|
|
|
|false|Write failure|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## readByte()
|
|
|
|
|
|
|
|
|
|
**Syntax:**
|
2020-11-05 11:39:06 +08:00
|
|
|
` bool readByte(uint8_t address, uint8_t *result);`
|
2019-05-02 14:04:24 +09:00
|
|
|
|
|
|
|
|
**Description:**
|
|
|
|
|
|
|
|
|
|
Read from the specified address.
|
|
|
|
|
It is used when there is no data to send before reading and the response is 1 byte.
|
|
|
|
|
|
|
|
|
|
**Function argument**
|
2019-05-02 14:24:19 +09:00
|
|
|
|
2019-05-02 14:04:24 +09:00
|
|
|
| Function argument |Type |Description |
|
|
|
|
|
| --- | --- | --- |
|
|
|
|
|
| address | <code>uint8_t</code> |Slave Address |
|
|
|
|
|
| result | <code>uint8_t *</code> | stored memory |
|
|
|
|
|
|
|
|
|
|
**Function return value**
|
2019-05-02 14:24:19 +09:00
|
|
|
|
2019-05-02 14:04:24 +09:00
|
|
|
| Value |Description |
|
|
|
|
|
| --- | --- |
|
|
|
|
|
|true|Read success|
|
|
|
|
|
|false|Read failure|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## readByte()
|
|
|
|
|
|
|
|
|
|
**Syntax:**
|
2020-11-05 11:39:06 +08:00
|
|
|
`bool readByte(uint8_t address, uint8_t subAddress,uint8_t *result);`
|
2019-05-02 14:04:24 +09:00
|
|
|
|
|
|
|
|
**Description:**
|
|
|
|
|
|
|
|
|
|
Read from the specified address.
|
|
|
|
|
It is used when the data to be sent before reading is only the functional address and the response is 1 byte.
|
|
|
|
|
|
|
|
|
|
**Function argument**
|
2019-05-02 14:24:19 +09:00
|
|
|
|
2019-05-02 14:04:24 +09:00
|
|
|
| Function argument |Type |Description |
|
|
|
|
|
| --- | --- | --- |
|
|
|
|
|
| address | <code>uint8_t</code> |Slave Address |
|
2019-05-02 14:24:19 +09:00
|
|
|
| subAddress | <code>uint8_t</code> |function address |
|
2019-05-02 14:04:24 +09:00
|
|
|
| result | <code>uint8_t *</code> |stored memory|
|
|
|
|
|
|
|
|
|
|
**Function return value**
|
2019-05-02 14:24:19 +09:00
|
|
|
|
2019-05-02 14:04:24 +09:00
|
|
|
| Value |Description |
|
|
|
|
|
| --- | --- |
|
|
|
|
|
|true|Read success|
|
|
|
|
|
|false|Read failure|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## readBytes()
|
|
|
|
|
|
|
|
|
|
**Syntax:**
|
2020-11-05 11:39:06 +08:00
|
|
|
`bool readBytes(uint8_t address, uint8_t count,uint8_t * dest);`
|
2019-05-02 14:04:24 +09:00
|
|
|
|
|
|
|
|
**Description:**
|
|
|
|
|
|
|
|
|
|
Read from the specified address.
|
|
|
|
|
Use when there is no data to send before reading and there are multiple responses.
|
|
|
|
|
|
|
|
|
|
**Function argument**
|
2019-05-02 14:24:19 +09:00
|
|
|
|
2019-05-02 14:04:24 +09:00
|
|
|
| Function argument |Type |Description |
|
|
|
|
|
| --- | --- | --- |
|
|
|
|
|
| address | <code>uint8_t</code> |Slave Address |
|
|
|
|
|
| count | <code>uint8_t</code> | Length of request bytes |
|
|
|
|
|
| result | <code>uint8_t *</code> |stored memory|
|
|
|
|
|
|
|
|
|
|
**Function return value**
|
2019-05-02 14:24:19 +09:00
|
|
|
|
2019-05-02 14:04:24 +09:00
|
|
|
| Value |Description |
|
2019-05-02 14:24:19 +09:00
|
|
|
| --- | --- |
|
2019-05-02 14:04:24 +09:00
|
|
|
|true|Read success|
|
|
|
|
|
|false|Read failure|
|
|
|
|
|
|
|
|
|
|
## readBytes()
|
|
|
|
|
|
|
|
|
|
**Syntax:**
|
2020-11-05 11:39:06 +08:00
|
|
|
`bool readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t * dest);`
|
2019-05-02 14:04:24 +09:00
|
|
|
|
|
|
|
|
**Description:**
|
|
|
|
|
|
|
|
|
|
Read from the specified address.
|
|
|
|
|
It is used when the data to be sent before reading is only the functional address and there are multiple responses.
|
|
|
|
|
|
|
|
|
|
**Function argument**
|
2019-05-02 14:24:19 +09:00
|
|
|
|
2019-05-02 14:04:24 +09:00
|
|
|
| argument |Typer |Description |
|
|
|
|
|
| --- | --- | --- |
|
|
|
|
|
| address | <code>uint8_t</code> |Slave Address |
|
|
|
|
|
| subAddress | <code>uint8_t</code> |Addresress |
|
|
|
|
|
| count | <code>uint8_t</code> | Length of request bytes |
|
|
|
|
|
| result | <code>uint8_t *</code> |stored memory|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**Function return value**
|
2019-05-02 14:24:19 +09:00
|
|
|
|
2019-05-02 14:04:24 +09:00
|
|
|
| Value |Description |
|
|
|
|
|
| --- | --- |
|
|
|
|
|
|true|Read success|
|
|
|
|
|
|false|Read failure|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## scanID()
|
|
|
|
|
|
|
|
|
|
**Syntax:**
|
2020-11-05 11:39:06 +08:00
|
|
|
`bool readBytes(bool *result);`
|
2019-05-02 14:04:24 +09:00
|
|
|
|
|
|
|
|
**Description:**
|
|
|
|
|
|
|
|
|
|
Perform device presence check on I2C bus.
|
|
|
|
|
|
|
|
|
|
**Function argument**
|
2019-05-02 14:24:19 +09:00
|
|
|
|
2019-05-02 14:04:24 +09:00
|
|
|
| Function argument |Type |Description |
|
|
|
|
|
| --- | --- | --- |
|
|
|
|
|
| result | <code>bool *</code> |stored memory(128bytes) |
|
|
|
|
|
|
|
|
|
|
**Function return value**
|
2019-05-02 14:24:19 +09:00
|
|
|
|
2019-05-02 14:04:24 +09:00
|
|
|
| Value |Description |
|
|
|
|
|
| --- | --- |
|
|
|
|
|
|true|Read success|
|
|
|
|
|
|false|Read failure|
|
|
|
|
|
|
2019-05-03 03:56:03 +09:00
|
|
|
**Example of use;**
|
2019-05-02 14:04:24 +09:00
|
|
|
|
2021-02-26 17:27:20 +08:00
|
|
|
```clike
|
2019-05-03 03:56:03 +09:00
|
|
|
bool result[0x80];
|
|
|
|
|
M5.I2C.scanID(&result[0]);
|
|
|
|
|
```
|