Hi, Nordic Team. I'm using BC805M EK (nRF52805). In my code, I'm using SAADC (PPI interruption), TWI, BLE and System ON/OFF button.
Q1) I don't need RTS, CTS on the UART. However, in uart_init() function, it is required to assign the pin number to RTS and CTS. What should I do, please?
Q2) On the BC805M development board, there is a switch to connect/disconnect the UART with nRF52805. It also has a reset button. I disabled the reset function and changed this button to the System ON/OFF button. If I connect the UART, the button function works fine. However, if I disconnect the UART, and delete all of the UART functions in the code : uart_event_handle() and uart_init(), the System ON/OFF button function doesn't work. Any idea, please?
Thank you!
void uart_event_handle(app_uart_evt_t * p_event)
{
static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
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') ||
(data_array[index - 1] == '\r') ||
(index >= m_ble_nus_max_data_len))
{
if (index > 1)
{
NRF_LOG_DEBUG("Ready to send data over BLE NUS");
NRF_LOG_HEXDUMP_DEBUG(data_array, index);
do
{
uint16_t length = (uint16_t)index;
err_code = ble_nus_data_send(&m_nus, data_array, &length, m_conn_handle);
if ((err_code != NRF_ERROR_INVALID_STATE) &&
(err_code != NRF_ERROR_RESOURCES) &&
(err_code != NRF_ERROR_NOT_FOUND))
{
APP_ERROR_CHECK(err_code);
}
} while (err_code == NRF_ERROR_RESOURCES);
}
index = 0;
}
break;
case APP_UART_COMMUNICATION_ERROR:
APP_ERROR_HANDLER(p_event->data.error_communication);
break;
case APP_UART_FIFO_ERROR:
APP_ERROR_HANDLER(p_event->data.error_code);
break;
default:
break;
}
}
//snippet [UART Initialization]
static void uart_init(void)
{
uint32_t err_code;
app_uart_comm_params_t const comm_params =
{
.rx_pin_no = 12, // BC805M EK: Rx = 12
.tx_pin_no = 16, // BC805M EK: Tx = 16
.rts_pin_no = 197,
.cts_pin_no = 196,
.flow_control = APP_UART_FLOW_CONTROL_DISABLED,
.use_parity = false,
#if defined (UART_PRESENT)
.baud_rate = NRF_UART_BAUDRATE_115200
#else
.baud_rate = NRF_UARTE_BAUDRATE_115200
#endif
};
APP_UART_FIFO_INIT(&comm_params,
UART_RX_BUF_SIZE,
UART_TX_BUF_SIZE,
uart_event_handle,
APP_IRQ_PRIORITY_LOWEST,
err_code);
APP_ERROR_CHECK(err_code);
}
#define BTN_ID 0
/**@brief Handler for shutdown preparation.
*/
bool shutdown_handler(nrf_pwr_mgmt_evt_t event)
{
uint32_t err_code;
switch (event)
{
case NRF_PWR_MGMT_EVT_PREPARE_WAKEUP:
NRF_LOG_INFO("NRF_PWR_MGMT_EVT_PREPARE_WAKEUP");
err_code = bsp_buttons_disable();
// Suppress NRF_ERROR_NOT_SUPPORTED return code.
UNUSED_VARIABLE(err_code);
err_code = bsp_wakeup_button_enable(BTN_ID);
// Suppress NRF_ERROR_NOT_SUPPORTED return code.
UNUSED_VARIABLE(err_code);
break;
}
err_code = app_timer_stop_all();
APP_ERROR_CHECK(err_code);
return true;
}
/**@brief Register application shutdown handler with priority 0. */
NRF_PWR_MGMT_HANDLER_REGISTER(shutdown_handler, 0);
/**@brief Function for handling BSP events.
*/
static void bsp_evt_handler(bsp_event_t evt)
{
#if NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_ENABLED
nrf_pwr_mgmt_feed();
NRF_LOG_INFO("Power management fed");
#endif // NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_ENABLED
switch (evt)
{
case BSP_EVENT_DEFAULT:
printf("1button pressed\r\n");
break;
case BSP_EVENT_SYSOFF:
printf("2button released\r\n");
// Application will prepare the wakeup mechanism: NRF_PWR_MGMT_EVT_PREPARE_WAKEUP
/**@brief Function for shutting down the system.
* @param[in] shutdown_type Type of operation.
* @details All callbacks will be executed prior to shutdown.
*/
// sd_power_system_off();
nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF);
// NRF_LOG_INFO("2) System OFF is entered\r\n");
// NRF_POWER->SYSTEMOFF = 1;
break;
default:
return; // no implementation needed
}
}
/**@brief Function for initializing the BSP module.
*/
static void bsp_configuration()
{
uint32_t err_code;
err_code = bsp_init(BSP_INIT_BUTTONS, bsp_evt_handler);
APP_ERROR_CHECK(err_code);
err_code = bsp_event_to_button_action_assign(BTN_ID,
BSP_BUTTON_ACTION_LONG_PUSH,
BSP_EVENT_DEFAULT);
APP_ERROR_CHECK(err_code);
err_code = bsp_event_to_button_action_assign(BTN_ID,
BSP_BUTTON_ACTION_RELEASE,
BSP_EVENT_SYSOFF);
APP_ERROR_CHECK(err_code);
}
// In pca10040.h, I did some modifications
#define BUTTONS_NUMBER 1
#define BUTTON_START 21
#define BUTTON_1 21
#define BUTTON_STOP 21
#define BUTTON_PULL NRF_GPIO_PIN_PULLUP
#define BUTTONS_ACTIVE_STATE 0
#define BUTTONS_LIST { BUTTON_1 }
#define BSP_BUTTON_0 BUTTON_1

