Hi,
I have a custom board connected with DK and i was able to program it and test some simple codes.
I need to test this TWI example on my board.
I uploaded it but i am not sure if sensor is working or not.
I need to see some data on some serial port or Segger studio.
Can you help me with it plz?
#include <stdio.h> #include "boards.h" #include "app_util_platform.h" #include "app_error.h" #include "nrf_drv_twi.h" #include "nrf_log.h" #include "nrf_log_ctrl.h" #include "nrf_log_default_backends.h" /* TWI instance ID. */ #if TWI0_ENABLED #define TWI_INSTANCE_ID 0 #elif TWI1_ENABLED #define TWI_INSTANCE_ID 1 #endif /* Number of possible TWI addresses. */ #define TWI_ADDRESSES 0x14 /* TWI instance. */ static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID); /** * @brief TWI initialization. */ void twi_init (void) { ret_code_t err_code; const nrf_drv_twi_config_t twi_config = { .scl = 27, .sda = 26, .frequency = NRF_DRV_TWI_FREQ_100K, .interrupt_priority = APP_IRQ_PRIORITY_HIGH, .clear_bus_init = false }; err_code = nrf_drv_twi_init(&m_twi, &twi_config, NULL, NULL); APP_ERROR_CHECK(err_code); nrf_drv_twi_enable(&m_twi); } /** * @brief Function for main application entry. */ int main(void) { ret_code_t err_code; uint8_t address; uint8_t sample_data; bool detected_device = false; APP_ERROR_CHECK(NRF_LOG_INIT(NULL)); NRF_LOG_DEFAULT_BACKENDS_INIT(); NRF_LOG_INFO("TWI scanner started."); NRF_LOG_FLUSH(); twi_init(); for (address = 1; address <= TWI_ADDRESSES; address++) { err_code = nrf_drv_twi_rx(&m_twi, address, &sample_data, sizeof(sample_data)); if (err_code == NRF_SUCCESS) { detected_device = true; NRF_LOG_INFO("TWI device detected at address 0x%x.", address); } NRF_LOG_FLUSH(); } if (!detected_device) { NRF_LOG_INFO("No device was found."); NRF_LOG_FLUSH(); } while (true) { /* Empty loop. */ } } /** @} */
By the way, I had to exclude SEGGER_RTT_Syscalls_SES.c from the project because it was giving me some printf issues.