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

Receiving data from GPS L80 with nrf52832 via UART

I am trying to receive data from GPS L80 with the nrf52832 board but I am not able to receive anything. I connected the Rx of nrf52832 with GPS and vice versa. I also connected the grounds of both these devices together. I am hereby attaching my code , Please help me regarding the same.

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "app_uart.h"
#include "app_error.h"
#include "nrf_delay.h"
#include "nrf.h"
#include "bsp.h"
#include "nrf_uart.h"

NRF_UART_Type uart1;

#define uart1_rx NRF_GPIO_PIN_MAP(0,22)
#define uart1_tx NRF_GPIO_PIN_MAP(0,23)

int main(void)
{
    nrf_uart_enable(&uart1);
    nrf_uart_txrx_pins_set(&uart1, 6, 8);
    nrf_uart_baudrate_set(&uart1,NRF_UART_BAUDRATE_115200);

char UART_RX_BUF[256];
int i=0;
    while (i<256)
    {   
        
        UART_RX_BUF[i] = nrf_uart_rxd_get(&uart1);
        i++;
    }

}

  • the nrf52832 board

    What nrf52832 board, exactly ?

    If it's Nordic's nRF52832-DK, remember that it has a USB-to-UART converter occupying some pins ...

    https://devzone.nordicsemi.com/f/nordic-q-a/49703/connecting-uart-data-to-development-board-pca10040/198110#198110

    I am not able to receive anything.

    Before adding the complications of 3rd-party external devices, have you tried the UART example in the SDK, and got that working?

    I connected the Rx of nrf52832 with GPS and vice versa

    How did you connect it, exactly?

    Show a schematic - trying to describe connections in text highly ineffective!

    How to properly post source code:

  • Hi,

    You do not assign any useful value to uart1. You should rather pass the existing symbol of NRF_UART_Type that is defined in nrf52.h: NRF_UART0.

    Best regards,
    Jørgen

  • Hello.

    I have run the already given UART example from examples/peripheral/uart and it seems to work fine. I tried to interconnect Tx and Rx of the board to see that if I am transmitting something, am I getting that back again. The uart1 structure when running the code shows everything that I have set i.e Tx and Rx pins that I have set manually also Tx data i.e 1 (just to check) but still I am getting getting 0 at Rx and also the buadrate is not been set. I am attaching the code as well as the snapshot of the uart1 structure when watched in watch. Please help.

    /**
     * Copyright (c) 2014 - 2019, Nordic Semiconductor ASA
     *
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    /** @file
     * @defgroup uart_example_main main.c
     * @{
     * @ingroup uart_example
     * @brief UART Example Application main file.
     *
     * This file contains the source code for a sample application using UART.
     *
     */
    
    #include <stdbool.h>
    #include <stdint.h>
    #include <stdio.h>
    #include "app_uart.h"
    #include "app_error.h"
    #include "nrf_delay.h"
    #include "nrf.h"
    #include "bsp.h"
    #include "nrf_uart.h"
    
    NRF_UART_Type uart1;
    
    //#define ENABLE_LOOPBACK_TEST  /**< if defined, then this example will be a loopback test, which means that TX should be connected to RX to get data loopback. */
    
    /*#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. */
    #define uart1_rx NRF_GPIO_PIN_MAP(0,22)
    #define uart1_tx NRF_GPIO_PIN_MAP(0,23)
    uint8_t tx_data = 1;
    uint8_t rx_data;
    
    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);
        }
    }
    
    
    
    /* When UART is used for communication with the host do not use flow control.*/
    #define UART_HWFC APP_UART_FLOW_CONTROL_DISABLED
    #endif
    
    
    /**
     * @brief Function for main application entry.
     */
    int main(void)
    {
        nrf_uart_enable(&uart1);
        nrf_uart_txrx_pins_set(&uart1, uart1_tx, uart1_rx);
        nrf_uart_baudrate_set(&uart1,NRF_UART_BAUDRATE_115200);
    
    char UART_RX_BUF[256];
    int i=0;
        while (i<256)
        {   
            nrf_uart_txd_set(&uart1,tx_data);
            rx_data = nrf_uart_rxd_get(&uart1);
            i++;
        }
    
    }
    
    
    
    

    Regards

  • The NRF_UART_Type is a reference to the actual hardware registers for the UART peripheral. You have created a new instance, but it will reference a random location in RAM. It will show the values you assign it, but these values will not be written to the registers. Replace &uart1 in the function calls with the already defined instance reference, NRF_UART0.

  • The uart1 structure when running the code shows everything that I have set

    But it doesn't show how you have physically connected to your GPS unit.

    I tried to interconnect Tx and Rx of the board to see that if I am transmitting something, am I getting that back again

    The next step is to connect to an external USB-to-UART, and verify that you can both send and receive over that.

    This will prove:

    1. That you can correctly configure the pins
    2. That you can correctly set the baud rate
    3. That you can correctly identify which is "Tx" and which is "Rx"

    A simple loopback doesn't confirm any of those.

    See here for more tips on serial debugging:

    https://www.avrfreaks.net/comment/2306116#comment-2306116

    https://www.avrfreaks.net/comment/2336161#comment-2336161

    Note the use of two terminals - so that you can see both Rx & Tx data ...

Related