diff --git a/code/b-parasite/Makefile b/code/b-parasite/Makefile index f98161b..1608e39 100644 --- a/code/b-parasite/Makefile +++ b/code/b-parasite/Makefile @@ -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 += \ diff --git a/code/b-parasite/config/sdk_config.h b/code/b-parasite/config/sdk_config.h index ee7c58e..522e720 100644 --- a/code/b-parasite/config/sdk_config.h +++ b/code/b-parasite/config/sdk_config.h @@ -4289,13 +4289,13 @@ // NRFX_TWI_ENABLED - nrfx_twi - TWI peripheral driver //========================================================== #ifndef NRFX_TWI_ENABLED -#define NRFX_TWI_ENABLED 0 +#define NRFX_TWI_ENABLED 1 #endif // NRFX_TWI0_ENABLED - Enable TWI0 instance #ifndef NRFX_TWI0_ENABLED -#define NRFX_TWI0_ENABLED 0 +#define NRFX_TWI0_ENABLED 1 #endif // NRFX_TWI1_ENABLED - Enable TWI1 instance @@ -4340,7 +4340,7 @@ // 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 // NRFX_TWI_CONFIG_LOG_LEVEL - Default Severity level @@ -5806,7 +5806,7 @@ // TWI_ENABLED - nrf_drv_twi - TWI/TWIM peripheral driver - legacy layer //========================================================== #ifndef TWI_ENABLED -#define TWI_ENABLED 0 +#define TWI_ENABLED 1 #endif // TWI_DEFAULT_CONFIG_FREQUENCY - Frequency @@ -5852,12 +5852,13 @@ // TWI0_ENABLED - Enable TWI0 instance //========================================================== #ifndef TWI0_ENABLED -#define TWI0_ENABLED 0 +#define TWI0_ENABLED 1 #endif // 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 @@ // 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 // TWI_CONFIG_LOG_LEVEL - Default Severity level diff --git a/code/b-parasite/src/main.c b/code/b-parasite/src/main.c index 5869e65..f483b91 100644 --- a/code/b-parasite/src/main.c +++ b/code/b-parasite/src/main.c @@ -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(); diff --git a/code/b-parasite/src/prst/shtc3.c b/code/b-parasite/src/prst/shtc3.c new file mode 100644 index 0000000..c1055a5 --- /dev/null +++ b/code/b-parasite/src/prst/shtc3.c @@ -0,0 +1,48 @@ +#include "prst/shtc3.h" + +#include +#include +#include +#include +#include + +// #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(); \ No newline at end of file diff --git a/code/b-parasite/src/prst/shtc3.h b/code/b-parasite/src/prst/shtc3.h new file mode 100644 index 0000000..8dadde8 --- /dev/null +++ b/code/b-parasite/src/prst/shtc3.h @@ -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_ \ No newline at end of file