app_uart_get() and app_uart_put()

Hi,

I want to use the functions app_uart_get() and app_uart_put() to communicate between the computer and NRF52840.

But when I type a string on the computer, the app_uart_get() function doesn't seem to receive it.

I'm using Segger Embedded Studio, the function app_uart_PUT()  is the same. What should I do?

  • Hello,

    But when I type a string on the computer

    Which program are you using for this?
    Are you seeing any output from the nRF in your serial terminal at all?

    I'm using Segger Embedded Studio, the function app_uart_PUT()  is the same. What should I do?

    Please show examples of how you have used these functions in your code, if possible. You can use the insert -> Code option here on DevZone when sharing code.

    Best regards,
    Karl

  • Thanks for your response, Karl.

    I hid some of the code that wasn't important. It goes like this:

    #include <stdbool.h>
    #include <stdint.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    #include "acc_integration.h"
    
    #include "acc_hal_definitions.h"
    #include "acc_hal_integration.h"
    #include "acc_rss.h"
    #include "acc_service.h"
    #include "acc_service_envelope.h"
    #include "acc_version.h"
    
    #include "sdk_config.h"
    #include "nrf_delay.h"
    #include "nrf_uart.h"
    #include "app_error.h"
    #include "nrf.h"
    #include "bsp.h"
    #include "nrf_uarte.h"
    #include "nrf_gpio.h"
    #include "nrf_drv_gpiote.h"
    #include "app_uart.h"
    #include "board_xm122.h"
    
    #define APP_UART_ENABLED 1
    #define APP_FIFO_ENABLED 1
    #define APP_UART_DRIVER_INSTANCE 0
    #define  UART_TX_BUF_SIZE 256
    #define  UART_RX_BUF_SIZE 256
    
    
    void uart_event_handler(app_uart_evt_t * p_event)
        	{
        		uint8_t c;
        		if(p_event->evt_type==APP_UART_COMMUNICATION_ERROR)
        			{
            				APP_ERROR_HANDLER(p_event->data.error_communication);
        			}
        		else if (p_event->data.error_code)
        			{
            				APP_ERROR_HANDLER(p_event->data.error_code);
        			}
    		else if (p_event->evt_type==APP_UART_DATA_READY)
        			{
    				app_uart_get(&c);
            				printf("the char received over uart is: %c\n",c);
        			}
        		else if (p_event->evt_type==APP_UART_TX_EMPTY)
        			{
            				printf("data is transmitted");
        			}
    	}
    
    void uart_config(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,
            				NRF_UARTE_BAUDRATE_115200
        			};
    
    
    APP_UART_FIFO_INIT(&comm_params,UART_RX_BUF_SIZE,UART_TX_BUF_SIZE,uart_event_handler,APP_IRQ_PRIORITY_LOW,err_code);
    APP_ERROR_CHECK(err_code);
    
    	}
    
    int acconeer_main(int argc, char *argv[]);
    int acconeer_main(int argc, char *argv[])
    	{
    	
    		uart_config();
    
            		while(1)
    			{
    			}
    
    
    	}
    

    When I downloaded the program into the chip, the computer's serial tool showed an error:

    Then I tried to input some characters, such as "111", "1223", etc. in the serial port tool of the computer terminal, but it didn't work.

    What should I do, please?

  • Hello again,

    Thank you for providing the full code and error message. The error message tells us that the function call on line 72 fails with the NRF_ERROR_INVALID_STATE error code

    Are you going to be using Hardware Flow control? If so, have you made sure to initialize the GPIOTE module before calling the app_uart_fifo_init?

    Best regards,
    Karl

  • Hi, Karl,

    Actually, I'm new to NRF52840.

    I want to implement UART serial communication so that the chip can respond to my commands.

    I programmed it following an instructional video. And I didn't see the initialization of the GPIOTE module in the video.

    As for the Hardware Flow control, APP_UART_FLOW_CONTROL_DISABLED is written in the code. I guess the Hardware Flow control is not used?

    I'm sorry I may not be a professional. What should I try to do next?

  • Jimmyh said:
    Actually, I'm new to NRF52840.

    That is no problem at all, thank you for letting me know - this makes it easier for me to adjust my answers.

    Jimmyh said:
    I want to implement UART serial communication so that the chip can respond to my commands.

    Have you seen any of the examples that does so already?
    If you are just starting out with Nordic development / a new project, I would highly recommend that you start using our nRF Connect SDK instead of the nRF5 SDK. Please see this statement for an elaboration of the distinction between the two.
    You can get started with the newest NCS release by following this documentation.

    Jimmyh said:
    I programmed it following an instructional video. And I didn't see the initialization of the GPIOTE module in the video.

    Which instructional video was this, and which SDK version did they use in the video?
    If you want to familiarize with the nRF Connect SDK I would highly recommend checking out this tutorial on the Nordic Academy page.

    Jimmyh said:
    I'm sorry I may not be a professional. What should I try to do next?

    That is no problem at all - we were all new to this at some point! :) 

    Please do not hesitate to ask if you should have any questions, or in the case that any part of my answer should be unclear.

    Best regards,
    Karl

Related