This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Simple UART code not working

Hi,

I started a project from scratch and I want to write a simple UART printf solution for debugging for my NRF52832 on PCA10040 DK. I know there's a LOG module but it seems too complicated for my use case.

I'm using sdk_config.h from examples/peripherals/uart, and I'm using a custom build system (it's googlable) using cmake. The system basically includes a module and all of its dependencies.

I tried uart example and everything works as it should so the pin numbers are correct and serial settings on PUTTY are correct. I tried lots of stuff but nothing seems to work. I'm flashing the code alongside SoftDevice, could that make a difference??? Any help is greatly appreciated. Thanks!

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>

#include "app_uart.h"
#include "bsp.h"
#if defined (UART_PRESENT)
#include "nrf_uart.h"
#endif
#if defined (UARTE_PRESENT)
#include "nrf_uarte.h"
#endif

const app_uart_comm_params_t uart_conf = {
    .rx_pin_no = 30,
    .tx_pin_no = 31,
    .rts_pin_no = RTS_PIN_NUMBER,
    .cts_pin_no = CTS_PIN_NUMBER,
    .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
    .use_parity = false,
    .baud_rate = NRF_UART_BAUDRATE_115200
};

int main(void)
{
    uint32_t err_code;
    bsp_board_init(BSP_INIT_LEDS);
    APP_UART_INIT(&uart_conf,
        NULL, APP_IRQ_PRIORITY_LOWEST, err_code);
    if (err_code == NRF_SUCCESS)
        bsp_board_leds_on();
    else
        bsp_board_leds_off();

    printf("\r\nHello\r\n");
    for(;;)
    {
        uint8_t ch = 0;
        while (app_uart_get(&ch) != NRF_SUCCESS);
        while (app_uart_put(ch) != NRF_SUCCESS);
        if (ch == 't')
        {
            bsp_board_leds_off();
            while(1)
            {
                ;
            }
        }
    }
    return 0;
}

Related