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?

Parents
  • 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?

Reply
  • 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?

Children
  • 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

  • Thanks Karl,

    Sorry for not replying these days. I have some other things to deal with recently.

    Thank you for recommending so many tutorials. But I don't have much time right now.

    I can't find the link to the tutorial video right now. He uses the Segger Embedded Studio sample project in the SDK-example-uart folder.

    But the project I used was a sample project from Acconeer that included SDK15.3. Because I bought their product for radar testing.

    The code in the tutorial video is almost the same as what I showed you before, and what it does is nrF52840 receives characters sent by the PC through the serial port tool (via the uart_app_get() function). The characters are then sent to the PC via the uart_app_put() function, which is also displayed via the serial port tool.

    Does the error message displayed by the serial port tool indicate that the serial port initialization function (APP_UART_FIFO_INIT()) failed? I read on the Internet that a similar error might have been initialized somewhere before. But WHEN I delete the initialization here, it still doesn't work.

    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?

    In my code, the flow control setting is APP_UART_FLOW_CONTROL_DISABLED. Does this mean nothing to do with the problem of uninitialized GPIOTE modules?

    What do you suggest I try next?

  • Jimmyh said:
    Sorry for not replying these days. I have some other things to deal with recently.

    No need to apologize - we'll continue this whenever you have the chance.

    Jimmyh said:
    Thank you for recommending so many tutorials.

    No problem at all, I am happy to help! :) 

    Jimmyh said:
    The code in the tutorial video is almost the same as what I showed you before, and what it does is nrF52840 receives characters sent by the PC through the serial port tool (via the uart_app_get() function). The characters are then sent to the PC via the uart_app_put() function, which is also displayed via the serial port tool.

    If this is all the functionality you need to implement for now you can take a look at how this is done in the UART peripheral example - it receives characters typed from a connected serial terminal on a computer, and can do things based on the received character.
    For example, you can modify it to send a specific character back once it receives a specific character, etc.
    Then, once you have confirmed this to work you can move back to your existing application and merge the functionality that is confirmed to work back into it. 

    Jimmyh said:
    In my code, the flow control setting is APP_UART_FLOW_CONTROL_DISABLED. Does this mean nothing to do with the problem of uninitialized GPIOTE modules?

    No, if you are not using hardware flow control you should not need to initialize GPIOTE first, but it looks to be what is causing the issue even still. Could you also share with me your sdk_config.h file, so that I may take a look to see if I can spot any potential issues?

    Best regards,
    Karl

Related