SHTC3 app to print id.

This commit is contained in:
Derek Jamison 2023-06-11 17:15:32 -05:00
parent 1d8134f778
commit 7a0540971e
4 changed files with 70 additions and 0 deletions

13
gpio/shtc3/README.md Normal file
View File

@ -0,0 +1,13 @@
# SHTC3
This is just a simple console application that uses i2c to communicate with an SHTC3 temperature and humidity device. It is assumed that you have debug mode turned on (Settings, System, Debug ON). To see the logs, either connect to serial port or use https://lab.flipper.net/cli and type ``log`` then enter. Once you are viewing the logs, run the application.
The code does the following:
- The address of the device is hard-coded to 0x70.
- Wake-up (0x3517) is sent to wake up the device.
- Read id (0xefc8) is sent to read the device ID.
- The output is expected to match "(xxxx1xxxxx000111)".
Resources:
- [I2CDevices.org info](https://i2cdevices.org/devices/shtc3)
- [SHTC3 Datasheet](https://www.waveshare.com/w/upload/3/33/SHTC3_Datasheet.pdf)

View File

@ -0,0 +1,10 @@
App(
appid="i2c_read_shtc3",
name="I2C SHTC3 Demo",
apptype=FlipperAppType.EXTERNAL,
entry_point="i2c_read_shtc3_app",
requires=["gui"],
stack_size=2 * 1024,
fap_icon="i2c_read_shtc3.png",
fap_category="GPIO",
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -0,0 +1,47 @@
#include <furi.h>
#include <furi_hal.h>
uint8_t address = 0x70 << 1;
uint32_t timeout = 1000;
FuriHalI2cBusHandle* i2c = &furi_hal_i2c_handle_external;
void wake_up() {
uint8_t data_wake_up[2] = {0x35, 0x17};
if(furi_hal_i2c_tx(i2c, address, data_wake_up, 2, timeout)) {
FURI_LOG_I("I2C", "Wake up success");
} else {
FURI_LOG_I("I2C", "Wake up failed");
}
}
void read_id() {
uint8_t data_read_id[2] = {0xef, 0xc8};
uint8_t data_response[3] = {0};
if(furi_hal_i2c_trx(i2c, address, data_read_id, 2, data_response, 3, timeout)) {
uint16_t value = (data_response[0] << 8) | data_response[1];
// put binary value into buffer and null terminate
char buffer[16];
for(uint8_t i = 0; i < 16; i++) {
buffer[15 - i] = (value & (1 << i)) ? '1' : '0';
}
buffer[16] = 0;
FURI_LOG_I("I2C", "Read ID: (%s) %04x", buffer, value);
FURI_LOG_I("I2C", "Expected ID: (xxxx1xxxxx000111)");
FURI_LOG_I("I2C", "CRC 8: %02x", data_response[2]);
} else {
FURI_LOG_I("I2C", "Read ID failed");
}
}
int32_t i2c_read_shtc3_app(void* p) {
UNUSED(p);
furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
wake_up();
read_id();
furi_hal_i2c_release(&furi_hal_i2c_handle_external);
return 0;
}