I can't print message on PuTTY terminal when i use UARTE

Hi, when I use other modules (like NRF_LOG ecc) no problem, when i use UART or UARTE the script is ok but i can't see anything on PuTTY terminal. In my case, a LED should toogle when I puty any button on keyboard (as it is) and print a message like "The character is x". 

That's the program I've written:

#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_uarte.h"


// Define a constant for TX & RX buffer size this size is really important and we can increase or decrease it
// according to our application, more buffer size means more RAM memory being used.
#define UART_TX_BUF_SIZE 64 // TX buffer size
#define UART_RX_BUF_SIZE 64 // RX buffer size


#define led 17 // define a pin for LED 1


// This event handler will be called whenever a uart event occurs
void uart_event_handler(app_uart_evt_t * p_event)
{

// create a varibale which will hold the characters that we are going to read over uart
uint8_t c;


// check if some communication error occured, this event will be trigered
if(p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
{
// Check the reason of error by accessing the error variable and then pass it to error handler
APP_ERROR_HANDLER(p_event->data.error_communication);
}

// check if fifo error occured, this might be fifo overflow or other relevant errors
else if (p_event->evt_type == APP_UART_FIFO_ERROR)
{
// Check the reason of error by accessing the error variable and then pass it to error handler
APP_ERROR_HANDLER(p_event->data.error_code);
}
// check if there is a character available to be read from the buffer
else if (p_event->evt_type == APP_UART_DATA_READY)
{
// Read the available character and store it in the variable
app_uart_get(&c);

// print a message over uart port along with the character information
printf("The char received over UART is: %c \r\n", c);
nrf_gpio_pin_toggle(led);
}

// check if the transmission over uart port is finished i.e. uart tx empty event was generated
else if (p_event->evt_type == APP_UART_TX_EMPTY)
{
// toggle an led or use any other function here
nrf_gpio_pin_toggle(led);
}


}

// A funtion that will configure the UART settings
void uart_config(void)
{
uint32_t err_code; // a variable to hold error value

const app_uart_comm_params_t comm_params = // a struct that will hold all the uart configurations
{
RX_PIN_NUMBER, // Mention the Pin number for RX pin
TX_PIN_NUMBER, // Mention the Pin number for TX pin
RTS_PIN_NUMBER, // Mention the Pin number for RTS pin
CTS_PIN_NUMBER, // Mention the Pin number for CTS pin
APP_UART_FLOW_CONTROL_DISABLED, // Disable the hardware flow control, we only need it if we are using high baud rates, we can save some pins by disabling this
false, // event parity if true, if false no parity
NRF_UARTE_BAUDRATE_115200 // make sure to write NRF_UARTE_BAUDRATE_115200 and not the NRF_UART_BAUDRATE_115200
};


// initialize the uart with the fifo and pass it the parameters
// Parameters = (configurations, rx buffer size, tx buffer size, event handler, interrupt priority, error code variable)
APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_event_handler, APP_IRQ_PRIORITY_LOWEST, err_code);
APP_ERROR_CHECK(err_code); // check if some error occured during initialization

}

/**
* @brief Function for main application entry.
*/
int main(void)
{

// configure the led pin as output pin
nrf_gpio_cfg_output(led);

// call the uart configuration function and now wait for the events from the uart
uart_config();

// infinite loop
while (true)
{
// perform some other tasks here, if uart event occurs the processor will automatically take care of the interrupts

}

}


Please, someone can help me? Thanks a lot!

Parents
  • Hello,

    Sorry for the late reply, but I was out off office after I got assigned with your ticket. 

    Let me see if I understand you correctly. 

    You can see the UART messages being printed in the Putty Terminal, but you can't write back to the nRF via UART?

    Please try to follow this description when you set up your PuTTy terminal. Ignore the part about RTT. 

    Alternatively, you can use another UART terminal. I usually use "Termite", whenever I need two way communication. 

    Best regards,

    Edvin

Reply
  • Hello,

    Sorry for the late reply, but I was out off office after I got assigned with your ticket. 

    Let me see if I understand you correctly. 

    You can see the UART messages being printed in the Putty Terminal, but you can't write back to the nRF via UART?

    Please try to follow this description when you set up your PuTTy terminal. Ignore the part about RTT. 

    Alternatively, you can use another UART terminal. I usually use "Termite", whenever I need two way communication. 

    Best regards,

    Edvin

Children
  • Hi Edvin,
    Thank you for your answer. I followed your advices on putty but them doesn't works. About Termite probably i should understand how it works.

    Thanks, regards.

  • Ok, i set Termite. It allow me to write what I write but it doesn't give me back a feedback when I switch on or switch off the led (like a message, as I coded, "Leds Turned On!!" or "Leds Turned Off!!")

  • Hello,

    What hardware are you running this application on? Is it an nRF52832 DK?

    Ste_ said:
    it doesn't give me back a feedback when I switch on or switch off the led (like a message, as I coded, "Leds Turned On!!" or "Leds Turned Off!!")

    I can't see where it is supposed to print that, but I guess you modified something in the uart_event_handler(). Is the uart_event_handler() triggered when you write a character? It could be that what you are seeing are issues because you are using the UART inside the UART event handler. Try just setting a variable inside the uart_event_handler() callback, and print from main if this is set (for testing/debugging purposes)

    Something like:

    // Near top of main.c:
    ...
    unit8_t received_byte = 0x00;
    
    uart_event_handler(...)
    {
        ...
        else if (p_event->evt_type == APP_UART_DATA_READY)
        {
            // Read the available character and store it in the variable
            app_uart_get(&c);
    
            // print a message over uart port along with the character information
            received_byte = c;
            printf("The char received over UART is: %c \r\n", c);
            nrf_gpio_pin_toggle(led);
        
        }
        ...
    }
    
    
    int main(void)
    {
        ...
        while (true)
        {
            if (received_byte != 0x00)
            {
                printf("received byte %c\r\n", received_byte);
                received_byte = 0x00;
            }
        }
    }

    And see if it prints anything then. 

    However, you should look into using the RTT log to print log messages, so that it will be independent of the UART. You can look into the SDK\examples\ble_peripheral\ble_app_uart example, as this has some nice UART handling that you can look at.

    Best regards,

    Edvin

  • Sorry, I mean this printable part in the code:

    // print a message over uart port along with the character information
    printf("The char received over UART is: %c \r\n", c);
    nrf_gpio_pin_toggle(led);
    }

    However, I tried the ble_app_uart example you said and I have the same problem

  • Ste_ said:

    However, I tried the ble_app_uart example you said and I have the same problem

    This suggests that putty is not set up correctly. Please check the link to set up the putty terminal from my initial reply. 

    Also, if you are testing the ble_app_uart, please note that this will not by default echo whatever you input back to the uart. 

    Did you try to move the printing (printf()) out of the uart event handler, like I suggested in the previous reply?

    Ste_ said:
    nrf_gpio_pin_toggle(led);

    Does this trigger? Are you sure you are not seeing an even amount of characters, so that the pin toggles a few times, ending up in the same state as it started? (It may be so quick that you don't see it). 

    If you are still stuck, please upload the application (zip and upload here using "drag and drop", so  that I can have a look. Describe what you expect the behavior to be, and what you observe, so that I can try to replicate this on a DK.

    Best regards,

    Edvin

Related