Hello,
I've been using the libuarte module in my project, and I done a power consumption reading. With libuarte switched on I'm consuming 0.78ma, and with it switched off is in the uA range. This means I need to turn it off when not in use and back on, when I need it.
Essentially I'm intialising/uninitialising the UART based on interrupts. When testing the code I'm getting the error message:
ERROR 3735928559 [Unknown error code] at C:\Users\yyy\Documents\yyy\yyy\nRF5_SDK_17.1.0_ddde560\modules\nrfx\drivers\src\nrfx_gpiote.c:473 PC at: 0x00020ABB
/**@brief Function for initializing the UART module.
*/
/**@snippet [UART Initialization] */
static void uart_init(void) {
uint32_t err_code;
nrf_libuarte_async_config_t nrf_libuarte_async_config = {
.tx_pin = TX_PIN_NUMBER,
.rx_pin = RX_PIN_NUMBER,
.baudrate = NRF_UARTE_BAUDRATE_57600,
.parity = NRF_UARTE_PARITY_EXCLUDED,
.hwfc = NRF_UARTE_HWFC_DISABLED,
.timeout_us = 200,
.int_prio = APP_IRQ_PRIORITY_LOW};
err_code = nrf_libuarte_async_init(&libuarte, &nrf_libuarte_async_config, uart_event_handler, (void *)&libuarte);
APP_ERROR_CHECK(err_code);
nrf_libuarte_async_enable(&libuarte);
}
volatile static bool uart_en_flag = false;
void ble_pdn_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
NRF_LOG_PROCESS();
ret_code_t err_code;
if (uart_en_flag)
NRF_LOG_INFO("Disabling UART");
uart_en_flag = false;
nrf_libuarte_async_uninit(&libuarte);
}
void ble_wakeup_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
NRF_LOG_PROCESS();
ret_code_t err_code;
adv_serv_data[1] = 0xAA;
adv_data_update(adv_serv_data);
if (!uart_en_flag)
{
NRF_LOG_INFO("Enabling UART");
err_code = nrf_drv_gpiote_init();
APP_ERROR_CHECK(err_code);
nrf_libuarte_async_config_t nrf_libuarte_async_config = {
.tx_pin = TX_PIN_NUMBER,
.rx_pin = RX_PIN_NUMBER,
.baudrate = NRF_UARTE_BAUDRATE_57600,
.parity = NRF_UARTE_PARITY_EXCLUDED,
.hwfc = NRF_UARTE_HWFC_DISABLED,
.timeout_us = 200,
.int_prio = APP_IRQ_PRIORITY_LOW};
err_code = nrf_libuarte_async_init(&libuarte, &nrf_libuarte_async_config, uart_event_handler, (void *)&libuarte);
APP_ERROR_CHECK(err_code);
nrf_libuarte_async_enable(&libuarte);
}
}
/**
* @brief Function for configuring two interrupt pins, and one output.
*/
static void gpio_init(void) {
ret_code_t err_code;
err_code = nrf_drv_gpiote_init();
APP_ERROR_CHECK(err_code);
/* Initialse LED as an output */
nrf_gpio_cfg_output(LED_1);
nrf_gpio_pin_set(LED_2);
nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
in_config.pull = NRF_GPIO_PIN_PULLUP;
err_code = nrf_drv_gpiote_in_init(BUTTON_1, &in_config, ble_pdn_handler);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_event_enable(BUTTON_1, true);
err_code = nrf_drv_gpiote_in_init(BUTTON_2, &in_config, ble_wakeup_handler);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_event_enable(BUTTON_2, true);
}
Calling nrf_libuarte_async_uninit(&libuarte) seems to work fine, but when trying to reinitialise the libuarte I'm getting the error above. It looks like from the error it has something to do with gpiote. Am I doing the process of of turning on/off the uart periperhal wrong?