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.
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.
if i use it in the serial program it is not working.
.
int main(void)
{
ret_code_t ret;
ret_code_t ret1;
ret = nrf_drv_clock_init();
APP_ERROR_CHECK(ret);
ret = nrf_drv_power_init(NULL);
APP_ERROR_CHECK(ret);
nrf_drv_clock_lfclk_request(NULL);
ret = app_timer_init();
APP_ERROR_CHECK(ret);
bsp_board_leds_init();
bsp_board_buttons_init();
ret = nrf_serial_init(&serial_uart, &m_uart0_drv_config, &serial_config);
APP_ERROR_CHECK(ret);
char *tx_message ;
int i = 12345;
tx_message = change(i);
ret = nrf_serial_write(&serial_uart,
tx_message,
strlen(tx_message),
NULL,
NRF_SERIAL_MAX_TIMEOUT);
printf("%d",i);
APP_ERROR_CHECK(ret);
while (true)
{
/* char c;
ret = nrf_serial_read(&serial_uart, &c, sizeof(c), NULL, 1000);
if (ret != NRF_SUCCESS)
{
continue;
}
(void)nrf_serial_write(&serial_uart, &c, sizeof(c), NULL, 0);
(void)nrf_serial_flush(&serial_uart, 0);
*/ ret = nrf_serial_write(&serial_uart,
tx_message,
strlen(tx_message),
NULL,
NRF_SERIAL_MAX_TIMEOUT);
// printf("%d",i);
ret = nrf_serial_write(&serial_uart,
"\n\r",
strlen(tx_message),
NULL,
NRF_SERIAL_MAX_TIMEOUT);
(void)nrf_serial_flush(&serial_uart, 0);
nrf_delay_ms(2000);
APP_ERROR_CHECK(ret);
}
}
which sdk version you are using?
sdk 14.2.0
it is working perfectly fine..i have checked it..
it is working perfectly fine..i have checked it..
/* 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);
}
}
}
/** @} */
i was using the serial example
is there any specific requirement of using serial example?? or else you can use uart example to print data on terminal.