0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Nordic Zigbee CLI Example の UART設定

Last updated at Posted at 2020-04-18

環境

  • nRF5_SDK_for_Thread_and_Zigbee_v4.0.0_dc7186b
  • nRF52840

プログラム

examplesのzigbeeディレクトリ中にある以下のうち、「cli」 を使います。

├── app_utils
│ └── ws2812
├── experimental
│ ├── cli ← コレ!
│ ├── light_control
│ ├── multi_sensor
│ └── multi_sensor_freertos
├── light_control
│ ├── light_bulb
│ ├── light_coordinator
│ └── light_switch
└── ota
├── bootloader
├── client
└── experimental_server

プログラム中では、 nRF52840 上の USB インターフェースまたは UART で CLI インターフェースが使用できます。

UART の通信条件は

  • 115200 bps
  • 8N1
  • ハードウェアフロー制御

となっています。以下のように配線します。

image.png

ハードウェアフロー制御ということで、RTS/CTS線の配線が必要でした。はて、どこにハードウェアフロー制御の記述があるのかな?

設定その1

実験に使用したのはオリジナルトレーニングボードであるアオノドン2019を使っていますが、公式の nRF52840-DK ボードの設定がそのまま使えるようになっています。
nRF52840-DK ボードは SDK 中では pca10056 として識別されていて、そのピンコンフィグレーションは (SDKディレクトリ)/components/boards/pca10056.h に記述されています。シリアル関係は以下のように記述されています。


# define RX_PIN_NUMBER  8
# define TX_PIN_NUMBER  6
# define CTS_PIN_NUMBER 7
# define RTS_PIN_NUMBER 5
# define HWFC           true


// serialization APPLICATION board - temp. setup for running serialized MEMU tests
# define SER_APP_RX_PIN              NRF_GPIO_PIN_MAP(1,13)    // UART RX pin number.
# define SER_APP_TX_PIN              NRF_GPIO_PIN_MAP(1,14)    // UART TX pin number.
# define SER_APP_CTS_PIN             NRF_GPIO_PIN_MAP(0,2)     // UART Clear To Send pin number.
# define SER_APP_RTS_PIN             NRF_GPIO_PIN_MAP(1,15)    // UART Request To Send pin number.

// serialization CONNECTIVITY board
# define SER_CON_RX_PIN              NRF_GPIO_PIN_MAP(1,14)    // UART RX pin number.
# define SER_CON_TX_PIN              NRF_GPIO_PIN_MAP(1,13)    // UART TX pin number.
# define SER_CON_CTS_PIN             NRF_GPIO_PIN_MAP(1,15)    // UART Clear To Send pin number. Not used if HWFC is set to false.
# define SER_CON_RTS_PIN             NRF_GPIO_PIN_MAP(0,2)     // UART Request To Send pin number. Not used if HWFC is set to false.

はて? 3つもあるけどこれらは何だろう?

調査していくと、以下の設定が Zigbee CLI Example の UART設定 に使われているものらしいです。


# define RX_PIN_NUMBER  8
# define TX_PIN_NUMBER  6
# define CTS_PIN_NUMBER 7
# define RTS_PIN_NUMBER 5
# define HWFC           true

上記に従って、以下のように接続します。

|nRF52840GPIO|アオノドン2019ピン|nRF52940信号名|シリアルモジュール信号名|
|:---:|:---:|:---:|
|8|RX|RX||TX|
|6|TX|TX||RX|
|7|GROVE2|CTS|RTS|
|5|GROVE1|RTS|CTS|
|GND|GND|GND|GND|

設定その2

(SDKディレクトリ)/components/zigbee/cli/zigbee_cli.c

にある


# if CLI_OVER_UART
    nrf_drv_uart_config_t uart_config = NRF_DRV_UART_DEFAULT_CONFIG;
    uart_config.pseltxd = TX_PIN_NUMBER;
    uart_config.pselrxd = RX_PIN_NUMBER;
    #if defined(HWFC) && (HWFC == true)
    uart_config.pselcts = CTS_PIN_NUMBER;
    uart_config.pselrts = RTS_PIN_NUMBER;
    uart_config.hwfc    = NRF_UART_HWFC_ENABLED;
    #endif
    ret = nrf_cli_init(&m_cli_uart, &uart_config, true, true, NRF_LOG_SEVERITY_NONE);
    APP_ERROR_CHECK(ret);
# endif

設定その3

先で参照されていた NRF_DRV_UART_DEFAULT_CONFIG は、

(sdkディレクトリ)/integration/nrfx/legacy/nrf_drv_uart.h

中で定義されています。


/**@brief UART default configuration. */
# define NRF_DRV_UART_DEFAULT_CONFIG                                          \
{                                                                            \
    .pseltxd            = NRF_UART_PSEL_DISCONNECTED,                        \
    .pselrxd            = NRF_UART_PSEL_DISCONNECTED,                        \
    .pselcts            = NRF_UART_PSEL_DISCONNECTED,                        \
    .pselrts            = NRF_UART_PSEL_DISCONNECTED,                        \
    .p_context          = NULL,                                              \
    .hwfc               = (nrf_uart_hwfc_t)UART_DEFAULT_CONFIG_HWFC,         \
    .parity             = (nrf_uart_parity_t)UART_DEFAULT_CONFIG_PARITY,     \
    .baudrate           = (nrf_uart_baudrate_t)UART_DEFAULT_CONFIG_BAUDRATE, \
    .interrupt_priority = UART_DEFAULT_CONFIG_IRQ_PRIORITY,                  \
    NRF_DRV_UART_DEFAULT_CONFIG_USE_EASY_DMA                                 \
}

設定その4

上で参照されていた、UART_DEFAULT_CONFIG_・・・ は、 sdk_config.h 中で定義されています。

例えば UART_DEFAULT_CONFIG_BAUDRATE は以下のようになり、


// <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

115200bps となっています。

ところで、 sdk_config.h 内には

UART_DEFAULT_CONFIG_BAUDRATE

だけではなく以下の設定もある。

NRFX_UART_DEFAULT_CONFIG_BAUDRATE

NRFX_UARTE_DEFAULT_CONFIG_BAUDRATE

がある。一体これらは何が違うのかな??

ハードウェアフロー制御を解除してみる

(SDKディレクトリ)/components/zigbee/cli/zigbee_cli.c

にある


    uart_config.hwfc    = NRF_UART_HWFC_ENABLED;

    uart_config.hwfc    =  NRF_UART_HWFC_DISABLED;

とすると解除できた。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?