Hi,
In my project NRF51422 need to communicate with two peripherals which are supporting only UART communication.
please help me if there is any possibility.
Thanks in advance.
Hi,
In my project NRF51422 need to communicate with two peripherals which are supporting only UART communication.
please help me if there is any possibility.
Thanks in advance.
Hi,
nRF51 series only support one UART. If you need to interface two UART devices, you need to switch the interface between the two devices. You can configure the UART interface on any GPIO on the chip.
If you need two simultaneous UARTs, you need to upgrade to nRF52840.
Best regards,
Jørgen
Thank you :)
Hi Jorgen ,
I have an issue by shifting this UART Configuration, i am using application timer for shifting.
I am trying to do like every 5 seconds i was calling timer handler, in that handler disabling previous UART connection by calling app_uart_stop(); and initializing new UART connection with different pin configuration.
Here both UARTS having there own handlers.
problem is that it is skipping some letters in both UART communication, Even though i was giving proper delay between app_uart_stop(); & new initialization of another UART.
my code is attached in documents.
thanks in advance./* 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"
#include "app_timer.h"
#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 1 /**< UART RX buffer size. */
#define APP_TIMER_PRESCALER 20
#define Ener_Me_time APP_TIMER_TICKS(5000, APP_TIMER_PRESCALER)
#define APP_TIMER_OP_QUEUE_SIZE 4
APP_TIMER_DEF(Shift_UART_timer);
void uart_error_handle(app_uart_evt_t * p_event)
{
if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
{
APP_ERROR_HANDLER(p_event->data.error_communication);
}
else if (p_event->evt_type == APP_UART_FIFO_ERROR)
{
APP_ERROR_HANDLER(p_event->data.error_code);
}
}
void uart_event_handle0(app_uart_evt_t * p_event)
{
static uint8_t data_array[20];
static uint8_t index = 0;
//uint32_t err_code;
switch (p_event->evt_type)
{
case APP_UART_DATA_READY:
UNUSED_VARIABLE(app_uart_get(&data_array[index]));
index++;
if((data_array[index-1]=='\n')||index>=20)
{
printf("\r\nCommand from ESP Module : %s\r\n",(char*)data_array);
}
break;
case APP_UART_COMMUNICATION_ERROR:
// APP_ERROR_HANDLER(p_event->data.error_communication); //commented by RAM
break;
case APP_UART_FIFO_ERROR:
//APP_ERROR_HANDLER(p_event->data.error_code); //commented by RAM
break;
default:
break;
}
}
void uart_event_handle1(app_uart_evt_t * p_event)
{
static uint8_t data_array[20];
static uint8_t index = 0;
//uint32_t err_code;
switch (p_event->evt_type)
{
case APP_UART_DATA_READY:
UNUSED_VARIABLE(app_uart_get(&data_array[index]));
index++;
if((data_array[index-1]=='\n')||index>=20)
{
printf("\r\nCommand from ARDUINO Module: %s\r\n",(char*)data_array);
}
break;
case APP_UART_COMMUNICATION_ERROR:
// APP_ERROR_HANDLER(p_event->data.error_communication); //commented by RAM
break;
case APP_UART_FIFO_ERROR:
//APP_ERROR_HANDLER(p_event->data.error_code); //commented by RAM
break;
default:
break;
}
}
void UART0_INIT()
{
uint32_t err_code;
const app_uart_comm_params_t comm_params =
{
RX_PIN_NUMBER0,
TX_PIN_NUMBER0,
RTS_PIN_NUMBER,
CTS_PIN_NUMBER,
APP_UART_FLOW_CONTROL_ENABLED,
false,
UART_BAUDRATE_BAUDRATE_Baud115200
};
APP_UART_FIFO_INIT(&comm_params,
UART_RX_BUF_SIZE,
UART_TX_BUF_SIZE,
uart_error_handle,
APP_IRQ_PRIORITY_LOW,
err_code);
APP_ERROR_CHECK(err_code);
printf("AT UART0\n");
nrf_delay_ms(20);
}
void UART1_INIT()
{
uint32_t err_code;
const app_uart_comm_params_t comm_params =
{
RX_PIN_NUMBER1,
TX_PIN_NUMBER1,
RTS_PIN_NUMBER,
CTS_PIN_NUMBER,
APP_UART_FLOW_CONTROL_ENABLED,
false,
UART_BAUDRATE_BAUDRATE_Baud115200
};
APP_UART_FIFO_INIT(&comm_params,
UART_RX_BUF_SIZE,
UART_TX_BUF_SIZE,
uart_error_handle,
APP_IRQ_PRIORITY_LOW,
err_code);
APP_ERROR_CHECK(err_code);
nrf_delay_ms(200);
printf("AT UART1\n");
nrf_delay_ms(200);
}
static void Energy_meter_Handler(void * p_context)
{
uint32_t err_code;
printf("PAUSE>\n");
nrf_delay_ms(20);
err_code=app_uart_close();
APP_ERROR_CHECK(err_code);
UART1_INIT();
printf("\r\nCommand for Energy meter\r\n");
nrf_delay_ms(200);
err_code=app_uart_close();
APP_ERROR_CHECK(err_code);
UART0_INIT();
printf("<RUN>\n");
}
void timer_int()
{
uint32_t err_code;
APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
err_code = app_timer_create(&Shift_UART_timer, APP_TIMER_MODE_REPEATED, Energy_meter_Handler);
APP_ERROR_CHECK(err_code);
err_code = app_timer_start(Shift_UART_timer,Ener_Me_time, NULL);
APP_ERROR_CHECK(err_code);
}
static void lfclk_request(void)
{
uint32_t err_code = nrf_drv_clock_init();
APP_ERROR_CHECK(err_code);
nrf_drv_clock_lfclk_request(NULL);
}
/**
* @brief Function for main application entry.
*/
int main(void)
{
lfclk_request();
timer_int();
UART0_INIT();
while(1)
{
}
}
Adding a delay is not an enforcer to make sure something is completed. Can you give some examples of what is output and what you expect?
Is the data_array variable that you store the chars in, in the handler, large enough to receive the whole message, and/or do you end the string with a '\n'?