Hi,
I want to use 2 UART(not need DMA) interface on my project. I know that SDK17 remove serial_uart example. So I call nrf_drv_uart_init() directly to use 2 UARTs.
My main function call initialize UART0 then initialize UART1. Initialize UART0 is ok. But I call to initialize UART1 by nrf_drv_uart_init(). The p_cb->state always stay on NRFX_DRV_STATE_INITIALIZED in below if function.
if (p_cb->state != NRFX_DRV_STATE_UNINITIALIZED)
{
err_code = NRFX_ERROR_INVALID_STATE;
NRFX_LOG_WARNING("Function: %s, error code: %s.",
__func__,
NRFX_LOG_ERROR_STRING_GET(err_code));
return err_code;
}
So, I always get error code = 8. Why? Is there something I missed? My source code as below.
Thank you.
John.
uart.c
#include <stdbool.h>
#include <stdint.h>
#include "nrf.h"
#include "app_error.h"
#include "bsp.h"
#include "nrf_delay.h"
#include "uart_driver.h"
#include "nrf_drv_uart.h"
static const nrf_drv_uart_t m_altery_uart = NRF_DRV_UART_INSTANCE(0);
static const nrf_drv_uart_config_t m_altery_uart_config = {
.pseltxd = ARTERY_TX_PIN_NUMBER,
.pselrxd = ARTERY_RX_PIN_NUMBER,
.pselrts = NRF_UART_PSEL_DISCONNECTED,
.pselcts = NRF_UART_PSEL_DISCONNECTED,
.p_context = NULL,
.interrupt_priority = UART_DEFAULT_CONFIG_IRQ_PRIORITY,
.hwfc = UART_DEFAULT_CONFIG_HWFC,
.parity = NRF_UART_PARITY_EXCLUDED,
.baudrate = (nrf_uart_baudrate_t)UART_DEFAULT_CONFIG_BAUDRATE
};
static const nrf_drv_uart_t m_key_uart = NRF_DRV_UART_INSTANCE(1);
static const nrf_drv_uart_config_t m_key_uart_config = {
.pseltxd = KEY_TX_PIN_NUMBER,
.pselrxd = KEY_RX_PIN_NUMBER,
.pselrts = NRF_UART_PSEL_DISCONNECTED,
.pselcts = NRF_UART_PSEL_DISCONNECTED,
.p_context = NULL,
.interrupt_priority = UART_DEFAULT_CONFIG_IRQ_PRIORITY,
.hwfc = UART_DEFAULT_CONFIG_HWFC,
.parity = NRF_UART_PARITY_EXCLUDED,
.baudrate = (nrf_uart_baudrate_t)UART_DEFAULT_CONFIG_BAUDRATE
};
static void key_uart_1_event_handler(nrf_drv_uart_event_t * p_event,
void * p_context)
{
(void)p_context;
switch (p_event->type)
{
case NRF_DRV_UART_EVT_ERROR:
break;
case NRF_DRV_UART_EVT_TX_DONE:
break;
case NRF_DRV_UART_EVT_RX_DONE:
break;
default:
APP_ERROR_CHECK(NRF_ERROR_INTERNAL);
}
}
static void altery_uart_0_event_handler(nrf_drv_uart_event_t * p_event,
void * p_context)
{
(void)p_context;
switch (p_event->type)
{
case NRF_DRV_UART_EVT_ERROR:
break;
case NRF_DRV_UART_EVT_TX_DONE:
break;
case NRF_DRV_UART_EVT_RX_DONE:
break;
default:
APP_ERROR_CHECK(NRF_ERROR_INTERNAL);
}
}
void altery_uart0_init()
{
ret_code_t err_code;
err_code = nrf_drv_uart_init(&m_altery_uart, &m_altery_uart_config, altery_uart_0_event_handler);
APP_ERROR_CHECK(err_code);
}
void key_uart1_init()
{
ret_code_t err_code;
err_code = nrf_drv_uart_init(&m_key_uart, &m_key_uart_config, key_uart_1_event_handler);
APP_ERROR_CHECK(err_code);
}
int main(void)
{
altery_uart0_init();
key_uart1_init();
}
My sdk_config.h
#ifndef NRFX_UARTE_ENABLED #define NRFX_UARTE_ENABLED 0 #endif // <o> NRFX_UARTE0_ENABLED - Enable UARTE0 instance #ifndef NRFX_UARTE1_ENABLED #define NRFX_UARTE1_ENABLED 0 #endif // <e> UART_ENABLED - nrf_drv_uart - UART/UARTE peripheral driver - legacy layer //========================================================== #ifndef UART_ENABLED #define UART_ENABLED 1 #endif // <o> UART_DEFAULT_CONFIG_HWFC - Hardware Flow Control // <0=> Disabled // <1=> Enabled #ifndef UART_DEFAULT_CONFIG_HWFC #define UART_DEFAULT_CONFIG_HWFC 0 #endif // <o> UART_DEFAULT_CONFIG_PARITY - Parity // <0=> Excluded // <14=> Included #ifndef UART_DEFAULT_CONFIG_PARITY #define UART_DEFAULT_CONFIG_PARITY 0 #endif // <o> UART_DEFAULT_CONFIG_BAUDRATE - Default Baudrate // <323584=> 1200 baud // <643072=> 2400 baud // <1290240=> 4800 baud // <2576384=> 9600 baud // <3862528=> 14400 baud // <5152768=> 19200 baud // <7716864=> 28800 baud // <10289152=> 38400 baud // <15400960=> 57600 baud // <20615168=> 76800 baud // <30801920=> 115200 baud // <61865984=> 230400 baud // <67108864=> 250000 baud // <121634816=> 460800 baud // <251658240=> 921600 baud // <268435456=> 1000000 baud #ifndef UART_DEFAULT_CONFIG_BAUDRATE #define UART_DEFAULT_CONFIG_BAUDRATE 30801920 #endif // <o> UART_DEFAULT_CONFIG_IRQ_PRIORITY - Interrupt priority // <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice // <0=> 0 (highest) // <1=> 1 // <2=> 2 // <3=> 3 // <4=> 4 // <5=> 5 // <6=> 6 // <7=> 7 #ifndef UART_DEFAULT_CONFIG_IRQ_PRIORITY #define UART_DEFAULT_CONFIG_IRQ_PRIORITY 6 #endif // <q> UART_EASY_DMA_SUPPORT - Driver supporting EasyDMA #ifndef UART_EASY_DMA_SUPPORT #define UART_EASY_DMA_SUPPORT 0 #endif // <q> UART_LEGACY_SUPPORT - Driver supporting Legacy mode #ifndef UART_LEGACY_SUPPORT #define UART_LEGACY_SUPPORT 1 #endif // <e> UART0_ENABLED - Enable UART0 instance //========================================================== #ifndef UART0_ENABLED #define UART0_ENABLED 1 #endif // <q> UART0_CONFIG_USE_EASY_DMA - Default setting for using EasyDMA #ifndef UART0_CONFIG_USE_EASY_DMA #define UART0_CONFIG_USE_EASY_DMA 0 #endif // </e> // <e> UART1_ENABLED - Enable UART1 instance //========================================================== #ifndef UART1_ENABLED #define UART1_ENABLED 1 #endif