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

2-line uart peripheral connection

Hi.

I've got little problem with the uart connection to one peripheral. It's a normal 2-line connection without HW flow control. I'm using app_uart_fifo. HW is nRF52 with sdk 11. I don't have uart tracing enabled in the package nor any other uart source files in the build.

Every write seems to be 256 bytes and contains only first byte sent. I don't have very good oscilloscope at disposal, so I can see clearly only couple of cycles at time. But the same pattern keeps repeating troughout the send. I get the TX done callback after each send. I also tested this so, that I outputted the UART output to terminal window and got tons of first letter in the sent string.

Setup is simple. The peripheral sends interrupt when it wants some input. It might be quite long time between queries. I only set status flag for the main loop. This is only for testing purposes and to keep things simple as possible. I've understood that the GPIOTE system can be used also for triggering context for doing this sort of things.

Base SW is pretty much ble central example that scans for blinky peripherals. I've also tried this with all other stuff removed, but interrupt enabling and status polling, but no change in behaviour. I have the softdevice flashed to hw, so I haven't tried without it yet.

Anyho this is the code:

static void uart_init(void){
    uint32_t                     err_code;
    const app_uart_comm_params_t comm_params =
    {
        RX_PIN_NUMBER,
        TX_PIN_NUMBER,
        RTS_PIN_NUMBER,
        CTS_PIN_NUMBER,
        APP_UART_FLOW_CONTROL_DISABLED,
        false,
        UART_BAUDRATE_BAUDRATE_Baud115200
    };

   APP_UART_FIFO_INIT( &comm_params,
                    UART_RX_BUF_SIZE,
                    UART_TX_BUF_SIZE,
                    uart_event_handle,
                    APP_IRQ_PRIORITY_LOW,
                    err_code);

   if (err_code != NRF_SUCCESS) {
       LEDS_ON(CENTRAL_SEND_LED);
   } else {
       LEDS_OFF(CENTRAL_SEND_LED);
   }
}

in output handler (called from main loop periodically):

void send_output() {
    uint8_t tx_data[] = "OUTPUT_TEST\n\r";

    if (update_needed) {
        int s = 0;
        payload_count = strlen(tx_data);
        while ( payload_count--) {
             while (app_uart_put(tx_data[s]) != NRF_SUCCESS);
             s++;
        }
    }
}
Related