Hi, I have modified the twi_scanner example of the 52840 DK to be compatible with nRFDongle.
I fully erased the dongle with Segger and passed the new hex file with SWD cable.
Then I connected an I2C device on the dongle and I can see with logic analyzer that the dongle
communicates with the I2C device properly by finding its address.
The problem I encounter is that the messages I want to print to the terminal with NRF_LOG_INFO() are not printed.
I also disabled the deferred mode in the sdk_config through CMSIS and commended the NRF_LOG_FLUSH();
If any ideas please share
Here is the code
#include <stdio.h>
#include "boards.h"
#include "app_util_platform.h"
#include "app_error.h"
#include "nrf_drv_twi.h"
#include "nrf_delay.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 127
// SDA and SCL pins for nRF Dongle 52840
#define TWI_SCL NRF_GPIO_PIN_MAP(1,13)
#define TWI_SDA NRF_GPIO_PIN_MAP(1,10)
/* 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 = TWI_SCL,
.sda = TWI_SDA,
.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();
bsp_board_init(BSP_INIT_LEDS);
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 == false) )
{
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();
}
else{
bsp_board_led_invert(2);
nrf_delay_ms(100);
bsp_board_led_invert(2);
}
while (true){
NRF_LOG_INFO("TWI device detected at address 0x%x.", address);
nrf_delay_ms(500);
}
}