nRF51 : Make the Printf to Work Well

本文介绍了一种解决Nordic UART示例中printf函数工作异常的问题,即只能打印出部分字符的情况。通过更换默认库文件,如将app_uart.c替换为app_uart_fifo.c等,并确保正确设置包含路径,可以实现完整的串口打印。
摘要由CSDN通过智能技术生成

     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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值