|
在写修改波特率时,查询了很多资料,发现nRF51822修改波特率直接修改寄存器即可。代码在单步执行时可以执行反馈OK,之后再次全速跑,就没有反应了。把波特率修改回原值后,仍可以跑,感觉波特率又被改回来了。询问大神,修改波特率具体的步骤如何?
执行代码如下:
else if((strcmp(at_cmd_name[5],data_array))==0) //判断接收到的
{
data_count = 0;
//NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Disabled << UART_ENABLE_ENABLE_Pos);
NRF_UART0->BAUDRATE=(UART_BAUDRATE_BAUDRATE_Baud19200 << UART_BAUDRATE_BAUDRATE_Pos);//ÉèÖò¨ÌØÂÊ19200
//NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);
if(NRF_UART0->BAUDRATE !=(UART_BAUDRATE_BAUDRATE_Baud19200 << UART_BAUDRATE_BAUDRATE_Pos))
{
simple_uart_putstring("ERROR\r\n");
}
else{
simple_uart_putstring("OK\r\n");
}
}
串口初始化代码:
void uart_init(void)
{
/**@snippet [UART Initialization] */
simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, HWFC);
NRF_UART0->INTENSET = UART_INTENSET_RXDRDY_Enabled << UART_INTENSET_RXDRDY_Pos;
NVIC_SetPriority(UART0_IRQn, APP_IRQ_PRIORITY_HIGH); //APP_IRQ_PRIORITY_LOW
NVIC_EnableIRQ(UART0_IRQn);
/**@snippet [UART Initialization] */
}
串口配置代码:
void simple_uart_config( uint8_t rts_pin_number, uint8_t txd_pin_number, uint8_t cts_pin_number, uint8_t rxd_pin_number, bool hwfc)
{ /** @snippet [Configure UART RX and TX pin] */
nrf_gpio_cfg_output(txd_pin_number);
nrf_gpio_cfg_input(rxd_pin_number, NRF_GPIO_PIN_NOPULL);
NRF_UART0->PSELTXD = txd_pin_number;
NRF_UART0->PSELRXD = rxd_pin_number;
/** @snippet [Configure UART RX and TX pin] */
if (hwfc) {
nrf_gpio_cfg_output(rts_pin_number);
nrf_gpio_cfg_input(cts_pin_number, NRF_GPIO_PIN_NOPULL);
NRF_UART0->PSELCTS = cts_pin_number;
NRF_UART0->PSELRTS = rts_pin_number;
NRF_UART0->CONFIG = (UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
}
NRF_UART0->BAUDRATE = (UART_BAUDRATE_BAUDRATE_Baud38400 << UART_BAUDRATE_BAUDRATE_Pos);
NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);
NRF_UART0->TASKS_STARTTX = 1;
NRF_UART0->TASKS_STARTRX = 1;
NRF_UART0->EVENTS_RXDRDY = 0;
}
粘贴过来排版有点乱了,大神请指教
|
|