Hello,
I am using nrf52 DK, and i have recently encountered a problem.
I am trying to measure the current of a the device during program execution, initially I didn't need the UART module so my current measurements were pretty clean.
Later on I needed to add the uart so added it to the config file.
My problem is that just activating the uart module in the config file (and initializing it), but without using it effects the current measurements significantly.
I added 2 figures that shows the frequencies of the current measurements of the same piece of code, on the first figure the uart module wasn't activated and on the second one it was activated and initialized but wasn't in use while the measurement occurred.
How can I minimize the effect of the uart module on the power measurements? I only need it to send a single byte, I dont need to receive anything and I dont care about the baud rate as well.
my code:
#include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <string.h> #include "app_uart.h" #include "app_error.h" #include "nrf.h" #include "nrf_delay.h" #include "nrf_gpio.h" #define gpio1 29 #define gpio2 30 #define button1 13 #include "bsp.h" #if defined (UART_PRESENT) #include "nrf_uart.h" #endif #if defined (UARTE_PRESENT) #include "nrf_uarte.h" #endif #define MAX_TEST_DATA_BYTES (15U) /**< max number of test bytes to be used for tx and rx. */ #define UART_TX_BUF_SIZE 256 /**< UART TX buffer size. */ #define UART_RX_BUF_SIZE 256 /**< UART RX buffer size. */ void uart_error_handle(app_uart_evt_t * p_event) { if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR) { APP_ERROR_HANDLER(p_event->data.error_communication); } else if (p_event->evt_type == APP_UART_FIFO_ERROR) { APP_ERROR_HANDLER(p_event->data.error_code); } } #define UART_HWFC APP_UART_FLOW_CONTROL_DISABLED void uart_init() { uint32_t err_code; const app_uart_comm_params_t comm_params = { RX_PIN_NUMBER, TX_PIN_NUMBER, RTS_PIN_NUMBER, CTS_PIN_NUMBER, UART_HWFC, false, #if defined (UART_PRESENT) NRF_UART_BAUDRATE_115200 #else NRF_UARTE_BAUDRATE_115200 #endif }; APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_error_handle, APP_IRQ_PRIORITY_LOWEST, err_code); APP_ERROR_CHECK(err_code); } void send_single_byte() { app_uart_put(Byte); } int main() { int results; uart_init(); nrf_gpio_cfg_output(gpio1); nrf_gpio_cfg_output(gpio2); nrf_gpio_cfg_input(button1,NRF_GPIO_PIN_PULLUP); while (nrf_gpio_pin_read(button1)==1); start_measurement(); result = some_computations(); stop_measurement(); send_single_byte(); nrf_delay_ms(250); while (true); }