Initial shtc3 TWI/I2C implementation
Weirdly, it only works ~1/5 of the time.
This commit is contained in:
parent
fb07a1244c
commit
02df5f4595
5 changed files with 73 additions and 8 deletions
|
|
@ -42,11 +42,13 @@ SRC_FILES += \
|
|||
$(SDK_ROOT)/modules/nrfx/mdk/system_nrf52840.c \
|
||||
$(SDK_ROOT)/components/boards/boards.c \
|
||||
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_clock.c \
|
||||
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_twi.c \
|
||||
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_uart.c \
|
||||
$(SDK_ROOT)/modules/nrfx/soc/nrfx_atomic.c \
|
||||
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_clock.c \
|
||||
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_gpiote.c \
|
||||
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_rtc.c \
|
||||
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_twi.c \
|
||||
$(SDK_ROOT)/modules/nrfx/drivers/src/prs/nrfx_prs.c \
|
||||
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_pwm.c \
|
||||
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_uart.c \
|
||||
|
|
@ -65,6 +67,7 @@ SRC_FILES += \
|
|||
$(PROJ_DIR)/prst/ble.c \
|
||||
$(PROJ_DIR)/prst/pwm.c \
|
||||
$(PROJ_DIR)/prst/rtc.c \
|
||||
$(PROJ_DIR)/prst/shtc3.c \
|
||||
|
||||
# Include folders common to all targets
|
||||
INC_FOLDERS += \
|
||||
|
|
|
|||
|
|
@ -4289,13 +4289,13 @@
|
|||
// <e> NRFX_TWI_ENABLED - nrfx_twi - TWI peripheral driver
|
||||
//==========================================================
|
||||
#ifndef NRFX_TWI_ENABLED
|
||||
#define NRFX_TWI_ENABLED 0
|
||||
#define NRFX_TWI_ENABLED 1
|
||||
#endif
|
||||
// <q> NRFX_TWI0_ENABLED - Enable TWI0 instance
|
||||
|
||||
|
||||
#ifndef NRFX_TWI0_ENABLED
|
||||
#define NRFX_TWI0_ENABLED 0
|
||||
#define NRFX_TWI0_ENABLED 1
|
||||
#endif
|
||||
|
||||
// <q> NRFX_TWI1_ENABLED - Enable TWI1 instance
|
||||
|
|
@ -4340,7 +4340,7 @@
|
|||
// <e> NRFX_TWI_CONFIG_LOG_ENABLED - Enables logging in the module.
|
||||
//==========================================================
|
||||
#ifndef NRFX_TWI_CONFIG_LOG_ENABLED
|
||||
#define NRFX_TWI_CONFIG_LOG_ENABLED 0
|
||||
#define NRFX_TWI_CONFIG_LOG_ENABLED 1
|
||||
#endif
|
||||
// <o> NRFX_TWI_CONFIG_LOG_LEVEL - Default Severity level
|
||||
|
||||
|
|
@ -5806,7 +5806,7 @@
|
|||
// <e> TWI_ENABLED - nrf_drv_twi - TWI/TWIM peripheral driver - legacy layer
|
||||
//==========================================================
|
||||
#ifndef TWI_ENABLED
|
||||
#define TWI_ENABLED 0
|
||||
#define TWI_ENABLED 1
|
||||
#endif
|
||||
// <o> TWI_DEFAULT_CONFIG_FREQUENCY - Frequency
|
||||
|
||||
|
|
@ -5852,12 +5852,13 @@
|
|||
// <e> TWI0_ENABLED - Enable TWI0 instance
|
||||
//==========================================================
|
||||
#ifndef TWI0_ENABLED
|
||||
#define TWI0_ENABLED 0
|
||||
#define TWI0_ENABLED 1
|
||||
#endif
|
||||
// <q> TWI0_USE_EASY_DMA - Use EasyDMA (if present)
|
||||
|
||||
|
||||
#ifndef TWI0_USE_EASY_DMA
|
||||
// #define TWI0_USE_EASY_DMA 1
|
||||
#define TWI0_USE_EASY_DMA 0
|
||||
#endif
|
||||
|
||||
|
|
@ -8944,7 +8945,7 @@
|
|||
// <e> TWI_CONFIG_LOG_ENABLED - Enables logging in the module.
|
||||
//==========================================================
|
||||
#ifndef TWI_CONFIG_LOG_ENABLED
|
||||
#define TWI_CONFIG_LOG_ENABLED 0
|
||||
#define TWI_CONFIG_LOG_ENABLED 1
|
||||
#endif
|
||||
// <o> TWI_CONFIG_LOG_LEVEL - Default Severity level
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
#include "prst/ble.h"
|
||||
#include "prst/pwm.h"
|
||||
#include "prst/rtc.h"
|
||||
|
||||
#include "prst/shtc3.h"
|
||||
#include "prst_config.h"
|
||||
|
||||
#define DEAD_BEEF 0xDEADBEEF
|
||||
|
|
@ -77,8 +77,11 @@ int main(void) {
|
|||
power_management_init();
|
||||
prst_ble_init();
|
||||
|
||||
prst_sht3c_init();
|
||||
prst_rtc_set_callback(rtc_callback);
|
||||
prst_rtc_init();
|
||||
NRF_LOG_FLUSH();
|
||||
// UNUSED_VARIABLE(prst_rtc_init());
|
||||
UNUSED_VARIABLE(prst_rtc_init));
|
||||
|
||||
for (;;) {
|
||||
power_manage();
|
||||
|
|
|
|||
48
code/b-parasite/src/prst/shtc3.c
Normal file
48
code/b-parasite/src/prst/shtc3.c
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#include "prst/shtc3.h"
|
||||
|
||||
#include <app_error.h>
|
||||
#include <nrf_delay.h>
|
||||
#include <nrf_drv_twi.h>
|
||||
#include <nrf_gpio.h>
|
||||
#include <nrf_log.h>
|
||||
|
||||
// #define PRST_SHT3C_DEFAULT_ADDR 0x70
|
||||
#define PRST_SHT3C_DEFAULT_ADDR 0x44
|
||||
|
||||
static const nrf_drv_twi_t twi_ = NRF_DRV_TWI_INSTANCE(0);
|
||||
|
||||
static uint8_t buff[6];
|
||||
static uint8_t tx_data[] = {0x2c, 0x06};
|
||||
|
||||
void prst_sht3c_init() {
|
||||
nrf_drv_twi_config_t twi_config = NRF_DRV_TWI_DEFAULT_CONFIG;
|
||||
twi_config.scl = NRF_GPIO_PIN_MAP(0, 3);
|
||||
twi_config.sda = NRF_GPIO_PIN_MAP(0, 28);
|
||||
// twi_config.clear_bus_init = true;
|
||||
twi_config.frequency = NRF_TWI_FREQ_400K;
|
||||
|
||||
uint32_t err_code;
|
||||
// uint8_t tx_data[] = {0x2c, 0x06};
|
||||
err_code = nrf_drv_twi_init(&twi_, &twi_config, NULL, NULL);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
nrf_drv_twi_enable(&twi_);
|
||||
nrf_delay_ms(10);
|
||||
err_code = nrf_drv_twi_tx(&twi_, PRST_SHT3C_DEFAULT_ADDR, tx_data,
|
||||
sizeof(tx_data), true);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
nrf_delay_ms(10);
|
||||
|
||||
NRF_LOG_INFO("WILL READ DATA:");
|
||||
err_code = nrf_drv_twi_rx(&twi_, PRST_SHT3C_DEFAULT_ADDR, buff, 6);
|
||||
NRF_LOG_INFO("OH NO!");
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
NRF_LOG_INFO("READ DATA: \n");
|
||||
for (int i = 0; i < 6; i++) {
|
||||
NRF_LOG_INFO("0x%d ", buff[i]);
|
||||
}
|
||||
NRF_LOG_INFO("Okay. \n");
|
||||
}
|
||||
|
||||
void prst_sht3c_read();
|
||||
10
code/b-parasite/src/prst/shtc3.h
Normal file
10
code/b-parasite/src/prst/shtc3.h
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef _PRST_SHT3C_H_
|
||||
#define _PRST_SHT3C_H_
|
||||
|
||||
typedef struct prst_sht3c_read {
|
||||
} prst_sh3c_read_t;
|
||||
|
||||
void prst_sht3c_init();
|
||||
void prst_sht3c_read();
|
||||
|
||||
#endif // _PRST_SHT3C_H_
|
||||
Loading…
Add table
Reference in a new issue