久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3602|回復: 1
打印 上一主題 下一主題
收起左側

NRF51822的一個串口通信例程源碼

[復制鏈接]
跳轉到指定樓層
樓主
ID:161493 發表于 2018-10-15 17:36 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
NRF51822的一個串口通信例程

單片機源程序如下:
  1. /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */

  12. #include <stdint.h>

  13. #include "nrf.h"
  14. #include "simple_uart.h"
  15. #include "nrf_delay.h"
  16. #include "nrf_gpio.h"

  17. uint8_t simple_uart_get(void)
  18. {
  19.   while (NRF_UART0->EVENTS_RXDRDY != 1)
  20.   {
  21.     // Wait for RXD data to be received
  22.   }
  23.   
  24.   NRF_UART0->EVENTS_RXDRDY = 0;
  25.   return (uint8_t)NRF_UART0->RXD;
  26. }

  27. bool simple_uart_get_with_timeout(int32_t timeout_ms, uint8_t *rx_data)
  28. {
  29.   bool ret = true;
  30.   
  31.   while (NRF_UART0->EVENTS_RXDRDY != 1)
  32.   {
  33.     if (timeout_ms-- >= 0)
  34.     {
  35.       // wait in 1ms chunk before checking for status
  36.       nrf_delay_us(1000);
  37.     }
  38.     else
  39.     {
  40.       ret = false;
  41.       break;
  42.     }
  43.   }  // Wait for RXD data to be received

  44.   if (timeout_ms >= 0)
  45.   {
  46.     // clear the event and set rx_data with received byte
  47.       NRF_UART0->EVENTS_RXDRDY = 0;
  48.       *rx_data = (uint8_t)NRF_UART0->RXD;
  49.   }

  50.   return ret;
  51. }

  52. void simple_uart_put(uint8_t cr)
  53. {
  54.   NRF_UART0->TXD = (uint8_t)cr;

  55.   while (NRF_UART0->EVENTS_TXDRDY!=1)
  56.   {
  57.     // Wait for TXD data to be sent
  58.   }

  59.   NRF_UART0->EVENTS_TXDRDY=0;
  60. }

  61. void simple_uart_putstring(const uint8_t *str)
  62. {
  63.   uint_fast8_t i = 0;
  64.   uint8_t ch = str[i++];
  65.   while (ch != '\0')
  66.   {
  67.     simple_uart_put(ch);
  68.     ch = str[i++];
  69.   }
  70. }

  71. void simple_uart_config(  uint8_t rts_pin_number,
  72.                           uint8_t txd_pin_number,
  73.                           uint8_t cts_pin_number,
  74.                           uint8_t rxd_pin_number,
  75.                           bool    hwfc)
  76. {
  77. /** @snippet [Configure UART RX and TX pin] */
  78.   nrf_gpio_cfg_output(txd_pin_number);
  79.   nrf_gpio_cfg_input(rxd_pin_number, NRF_GPIO_PIN_NOPULL);  

  80.   NRF_UART0->PSELTXD = txd_pin_number;
  81.   NRF_UART0->PSELRXD = rxd_pin_number;
  82. /** @snippet [Configure UART RX and TX pin] */
  83.   if (hwfc)
  84.   {
  85.     nrf_gpio_cfg_output(rts_pin_number);
  86.     nrf_gpio_cfg_input(cts_pin_number, NRF_GPIO_PIN_NOPULL);
  87.     NRF_UART0->PSELCTS = cts_pin_number;
  88.     NRF_UART0->PSELRTS = rts_pin_number;
  89.     NRF_UART0->CONFIG  = (UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
  90.   }

  91.   NRF_UART0->BAUDRATE         = (UART_BAUDRATE_BAUDRATE_Baud115200 << UART_BAUDRATE_BAUDRATE_Pos);
  92.   NRF_UART0->ENABLE           = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);
  93.   NRF_UART0->TASKS_STARTTX    = 1;
  94.   NRF_UART0->TASKS_STARTRX    = 1;
  95.   NRF_UART0->EVENTS_RXDRDY    = 0;
  96. }



  97. /**********************************************
  98. * 函數功能:串口處理
  99. * 入口參數:無
  100. * 返回值:無
  101. **********************************************/
  102. void Usart_Pro(void)
  103. {
  104.         simple_uart_putstring("123456\r\n");
  105. }


復制代碼

所有資料51hei提供下載:
NRF51822_USART.7z (321.13 KB, 下載次數: 39)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:442911 發表于 2018-12-27 22:02 | 只看該作者
good job
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 亚洲国产精品一区二区第一页 | 日本在线视频一区二区 | 精品日韩一区 | 伊人久麻豆社区 | 久久亚洲一区二区三区四区 | 日韩色图在线观看 | 国产精品1区2区3区 欧美 中文字幕 | 久久综合av | 中文字幕一区二区三区四区五区 | 91精品国产综合久久精品 | 国产精品国产三级国产a | 毛片免费视频 | 久久久久久国产精品三区 | 国产精品欧美一区二区三区不卡 | av一区二区三区四区 | 一区在线观看 | 久久久青草婷婷精品综合日韩 | 国产人成精品一区二区三 | 在线不卡视频 | 日韩欧美在线视频播放 | 欧美性影院 | 欧美老妇交乱视频 | 日本特黄a级高清免费大片 国产精品久久性 | 久草成人网 | 日日夜夜天天 | 国产高清视频一区二区 | 一级毛片成人免费看a | 曰韩三级 | 91久久久久久 | 日本在线观看视频 | 久久亚洲国产精品日日av夜夜 | 中文天堂在线一区 | 久久丁香| 伊人亚洲 | 欧美嘿咻 | 99久久久无码国产精品 | 国产福利免费视频 | 日韩黄色av | 免费v片在线观看 | 亚洲综合中文字幕在线观看 | 三级在线视频 |