您的位置:首页 > 产品设计 > UI/UE

nRF51 : Make the Printf to Work Well

2017-01-04 14:20 375 查看
     You may encounter a problem that when you follow the standard UART(Universal Asynchronous Receiver/Transmitter) step, but the printf would not work well. the Standard UART code in Nordic example be  (based on ):

/**@brief Function for the Power manager.
*/
static void power_manage(void)
{
uint32_t err_code = sd_app_evt_wait();
APP_ERROR_CHECK(err_code);
}

#include "app_uart.h"

#define UART_TX_BUF_SIZE  (256)
#define UART_RX_BUF_SIZE  (256)

/**
* @brief UART events handler.
*/
void uart_events_handler(app_uart_evt_t * p_event)
{
switch (p_event->evt_type)
{
case APP_UART_DATA_READY:
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;

case APP_UART_TX_EMPTY:
break;

case APP_UART_DATA:
break;

default:
break;
}
}

/**
* @brief UART initialization.
*/
void uart_config(void)
{
uint32_t                     err_code;
const app_uart_comm_params_t comm_params =
{
RX_PIN_NUMBER,
TX_PIN_NUMBER,
RTS_PIN_NUMBER,
CTS_PIN_NUMBER,
APP_UART_FLOW_CONTROL_DISABLED,
false,
UART_BAUDRATE_BAUDRATE_Baud38400
};

APP_UART_FIFO_INIT(&comm_params,
UART_RX_BUF_SIZE,
UART_TX_BUF_SIZE,
uart_events_handler,
APP_IRQ_PRIORITY_LOW,
err_code);

APP_ERROR_CHECK(err_code);
}

/**@brief Function for application main entry.
*/
int main(void)
{
uint32_t err_code;
bool erase_bonds;

uart_config();
printf("Start...\r\n");

// Initialize.


You will find that the output be :

S


,instead of full "Start". It prints the first byte always.

To solve this insufficient it very knack but simple :

Your default including libraries should be like this :

 

  Replace the  components\libraries\uart\app_uart.c as components\libraries\uart\app_uart_fifo.c and components\libraries\fifo\app_fifo.c





And do not forget to add the corresponding including path ..\..\..\..\..\..\components\libraries\fifo and ..\..\..\..\..\..\components\libraries\uart





And now your printf would work well:

Start...


Replace the nrf
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息