How do reset the UART if it is abnormal in NCS 2.6.1 ?
How do reset the UART if it is abnormal in NCS 2.6.1 ?
Hi
The easiest thing would be to reset/power cycle the board by powering it off and on again, but if you refer to how to "reset" the UART in code, it would be something like the following by uninitializing and reinitializing the UART peripheral:
if (uarte_initialized) {
nrfx_uarte_uninit(&uarte);
/* Workaround: uninit does not clear events, make sure all events are cleared. */
nrfy_uarte_int_init(uarte.p_reg, 0xFFFFFFFF, 0, false);
uarte_initialized = false;
}
// Re-initialize the UARTE peripheral with the same configuration
nrfx_uarte_config_t config = NRFX_UARTE_DEFAULT_CONFIG;
config.pseltxd = TX_PIN; // Replace TX_PIN with your actual TX pin number
config.pselrxd = RX_PIN; // Replace RX_PIN with your actual RX pin number
config.baudrate = NRF_UARTE_BAUDRATE_115200; // Example baud rate
// Check if re-initialization was successful
if (nrfx_uarte_init(uarte, &config, NULL) != NRFX_SUCCESS) {
printk("Failure during init \n");
} else {
printk("Success \n");
}
Best regards,
Simon
Hi:
The question is based on NCS 2.6.1, not old nRF SDK ,Uart can not receive data, how to restore ?
The principle is the same for NCS as well, you should still uninit the UART driver and reinitialize it. The nrfx driver calls should be the same in NCS, so the snippet should be a lot of the same code.
Best regards,
Simon