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

how to display integer value on putty using uart?

i was using the serial example in examples/peripheral/serial and i Want to display integer value int i=1234 on the serial terminal(putty).I want to convert the int value to string.

  • /* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
     *
     * The information contained herein is property of Nordic Semiconductor ASA.
     * Terms and conditions of usage are described in detail in NORDIC
     * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
     *
     * Licensees are granted free, non-transferable use of the information. NO
     * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
     * the file.
     *
     */
    
    /** @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"
    
    //#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. */
    
    uint8_t temp[8] = {1,2,3,4,5,6,7,8};
    
    void uart_event_handle(app_uart_evt_t * p_event)
    {
    
    }
    
    /**@brief Function for initializing the UART.
     */
    static void uart_init(void)
    {
        uint32_t err_code;
    
        const app_uart_comm_params_t comm_params =
          {
            
    				//default pin for 52
    			.rx_pin_no    = RX_PIN_NUMBER,
    			.tx_pin_no    = TX_PIN_NUMBER,
    			
          //.tx_pin_no    = ARDUINO_A0_PIN ,  //, TX_PIN_NUMBER// //K - edit
    				
    		//	.rx_pin_no    = ARDUINO_A1_PIN  ,
    
            .rts_pin_no   = RTS_PIN_NUMBER,
            .cts_pin_no   = CTS_PIN_NUMBER,
            .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
            .use_parity   = false,
            .baud_rate    = 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);
    
        APP_ERROR_CHECK(err_code);
    }
    
    
    
    
    /**
     * @brief Function for main application entry.
     */
    int main(void)
    {
       uart_init();
    	
    	//printf("%d\r\n",variable);
    	nrf_delay_ms(1000);
    	uint16_t temp1 = 1234;
    	for(;;){
    	 for (int i = 0;i<7;i++)
        {
    		printf("%d\r\n",temp1);
    
    			nrf_delay_ms(1000);
    		}
    	}
    }
    
    
    /** @} */
    

  • is there any specific requirement of using serial example?? or else you can use uart example to print data on terminal.

Related