🤖
LinkIt 7697 BlocklyDuino 使用指南
  • LinkIt 7697 BlocklyDuino 使用指南
    • 認識 LinkIt 7697
    • 認識 BlocklyDuino
    • BlocklyDuino v2 & v3 比較
    • 安裝開發環境 (v2)
      • 安裝 Arduino 編輯器
      • 安裝驅動並連接開發板
      • 安裝 BlocklyDuino 編輯器
      • 連結兩個編輯器並上傳程式
    • 安裝開發環境 (v3)
    • BlocklyDuino 基礎操作
    • 實作範例教學
      • A01. 內建 LED 閃爍
      • A02. 外接 LED 閃爍
      • A03. 外接 LED 呼吸燈
      • A04. RGB LED 顏色變化
      • A05. 外部按鈕控制開關
      • A06. 蜂鳴器播放聲音
      • A07 .可變電阻控制電壓輸出
      • A08. 伺服馬達控制
      • A21. DHT: 溫濕度感應器
      • A22. HTU21D: 溫溼度感應器
      • A23. PMSX003: PM2.5 感測器
      • A24. HC-SR04P: 超音波測距
      • A25. ADXL345: 加速規(動態)
      • A26. ADXL345: 加速規(手勢)
      • A27. 1602/2004: 液晶顯示模組
      • A28. WS2812: RGB 彩色燈條
      • A29. MFRC522: RFID
      • B00. Grove 相關基礎知識
      • B01. Grove 光感應器
      • B02. Grove 超音波測距感應器
      • B03. Grove 溫溼度感應器
      • B04. Grove 繼電器
      • B05. Grove LED 燈條
      • B06. Grove OLED 顯示器
      • C01. 雲端控制 LED 開關
      • C02. 上傳溫溼度到雲端
      • D01. 手機透過 BLE 讀寫裝置資料
      • E01. 遙控器: 按鈕控制 LED
    • 資源鏈結
  • LinkIt 7697 - Arduino IDE 開發指南
    • 環境設定
      • 設定 Arduino IDE
      • 將 LinkIt 7697 連接到電腦
        • 在 Windows 上安裝 CP2102N 驅動程式
        • 在 macOS 上安裝 CP2102N 驅動程式
      • 執行第一個程式
    • 開發指南
      • GPIO
      • UART
      • ADC
      • EINT (外部中斷 / External Interrupt)
      • I2C
      • SPI
      • EEPROM
      • Timer
      • Flash (索引式儲存空間)
      • RTC (Real-Time Clock)
      • Software Serial
      • 使用 Wi-Fi 函式庫
      • 使用 MCS 函式庫
        • 連接到 MCS
        • 連接到 MCSLite
          • 建立可透過 MCS Lite 控制的 Beacon
        • MCS 函式庫 API 使用手冊
          • MCSDevice
          • MCSLiteDeviceMCSLiteDevice
          • MCSDataChannel 相關類別
      • 使用 BLE 低功耗藍牙
        • 藍牙信標
        • 主控裝置
        • 周邊裝置
        • 已知限制
        • LBLE API 指南
          • LBLE
          • LBLECentral
          • LBLEPeripheral
          • LBLEAdvertisementData
          • LBLEService
          • LBLECharacteristic
          • LBLEAddress
          • LBLEUuid
          • LBLEClient
      • 使用 LinkIt Remote
        • LRemote API
        • LRemote 控制元件 API
      • LinkIt 7697 腳位的初始狀態
      • LinkIt 7697 供電說明
      • 更新 Bootloader 與韌體
      • Flash 燒錄工具
      • FOTA 更新
      • LinkIt 7697 的功能限制
      • 自行編譯 Arduino Package
      • 回報問題
    • 週邊元件連接教學
      • SMD 按鈕
      • RGB 三色 LED
      • 可變電阻
      • 九軸感應器 (MPU-9250)
      • 溫度與濕度感應器 (AM2302)
      • 超音波距離感應器
      • 光感應器 (LM358)
      • 0.96 吋 OLED 顯示模組 (SSD1308Z)
      • 長條型 LED 顯示模組 (MY9221)
      • 繼電器
      • 伺服馬達 (EMAX 9g ES08A Servo)
      • 使用 74HC595 驅動七段顯示器
      • 使用 MAX7219 驅動七段顯示器
      • 使用 MAX7219 驅動 8x8 矩陣式顯示器
      • 使用 OLED 模組 (如 SH1106 / SSD1306... 等模組)
      • 使用 PCF8574 / PCF8574A 驅動 1602 LCD
    • 開發套件與擴充板
      • Grove Starter Kit
      • Robot Shield
        • OTTO97
    • 下載
    • 資源連結
    • BSP 版本更新資訊
  • LinkIt 7697 - Development Guide for Arduino IDE
    • Environment Setup
      • Setup Arduino IDE
      • Connecting LinkIt 7697 to Computer
        • Install CP2102N Driver on Windows
        • Install CP2102N Driver on macOS
      • Run Your First Sketch
    • Developer Guide
      • GPIO
      • UART
      • ADC
      • External Interrupt
      • I2C
      • SPI
      • EEPROM
      • Timer
      • Flash (Key-Pair Storage)
      • RTC (Real-Time Clock)
      • Software Serial
      • Using the Wi-Fi Library
      • Using MCS Library
        • Connecting to MCS
        • Connecting to MCSLite
          • Build a Beacon controlled by MCS Lite
        • MCS Library API Reference
          • MCSDevice
          • MCSLiteDevice
          • MCSDataChannel Classes
      • Using Bluetooth
        • Beacons
        • Central Devices
        • Peripheral Devices
        • Limitations of LBLE library
        • LBLE Library API Guide
          • LBLE
          • LBLECentral
          • LBLEPeripheral
          • LBLEAdvertisementData
          • LBLEService
          • LBLECharacteristic
          • LBLEAddress
          • LBLEUuid
          • LBLEClient
      • Using LinkIt Remote
        • LRemote
        • LRemote Control Classes
      • Initial Pin State of LinkIt 7697
      • Powering the LinkIt 7697
      • Update Bootloader and Firmware
      • Flash Uploading Tool
      • FOTA Update
      • Limitations of LinkIt 7697
      • Source Code of Arduino Package
      • Issue Report
    • Tutorial
      • SMD Buttons
      • RGB LED
      • Potentiometer
      • IMU 9DOF v2.0 (MPU-9250)
      • Temperature and Humidity Sensor Pro (AM2302)
      • Grove Ultrasonic Ranger
      • Light Sensor (LM358)
      • Grove OLED Display 0.96" (SSD1308Z)
      • LED Bar v2.0 (MY9221)
      • Relay
      • Mini Servo (EMAX 9g ES08A Servo)
      • Driving 7-segment Displays with 74HC595
      • Driving 7-segment Displays with MAX7219
      • Driving 8x8 Dot Matrices with MAX7219
      • Using OLED module (SH1106 / SSD1306... etc.)
      • Driving 1602 LCD with PCF8574 / PCF8574A
    • Kits and Shields
      • Grove Starter Kit
      • Robot Shield
        • OTTO97
    • Download
    • Resources
    • BSP Release Notes
Powered by GitBook
On this page
  • 使用 SoftwareSerial 函式庫
  • 為何需要 SoftwareSerial?
  • 實作細節
  1. LinkIt 7697 - Arduino IDE 開發指南
  2. 開發指南

Software Serial

PreviousRTC (Real-Time Clock)Next使用 Wi-Fi 函式庫

Last updated 3 years ago

透過使用 SoftwareSerial 函式庫,開發者能在 LinkIt 7697 上連接更多的 UART/Serial 裝置。

要使用 SoftwareSerial 需要安裝 Arduino BSP v0.10.7 或更新的版本,並可在 Examples > SoftwareSerial 選單中看到範例程式。

使用 SoftwareSerial 函式庫

使用 SoftwareSerial 時,需要先指定 TX 與 RX 腳位。任何一隻數位針腳皆可當作 TX 使用,但是 RX 腳位僅能選擇 P2 或是 P3 (*),因為只有這兩隻腳位有支援 EINT 功能。下列程式碼示範將 TX 設成 P11、RX 設成 P2:

(*) 雖然 P1 和 P6 也同樣具有 EINT 功能,但因它們分屬 HW UART 以及 bootstrapping 腳位,故不建議拿來當 Software Serial 使用。

SoftwareSerial mySerial(2, 11); // RX, TX

設置好 TX 與 RX 腳位後,就可如同使用內建的 Serial 類別一般,直接呼叫 begin() 和 print() 等函式進行操作:

mySerial.begin(4800);	// supports up to 115200
mySerial.println("Hello, world?");

為何需要 SoftwareSerial?

雖然 LinkIt 7697 有兩組 HW serial (UART) 通訊埠:Serial 與 Serial1,但因以下使用情境限制:

  • 大多時候 Serial 通訊埠被拿來當作 debug 用途,連接 Serial Monitor 等工具看系統訊息而無法移作他用;

  • Serial1 通訊埠使用的 P6 腳位同時也是系統的 bootstrapping 腳位,在系統開機時它必須保持為低電位。相反地由於 UART 裝置在 idle 時訊號都是處在高電位,這會造成當 P6 連接 UART 裝置時會無法正常重新開機 (無法正常開機時,使用者會從 Serial Monitor 看到 "CCCCC...." 等字樣列印出來),需要配置額外的外部電路來確保該 UART 裝置必須在 MT7697 開機後才開始作用,如此才能保證 P6 的 bootstrapping 腳位不受影響。

因此當開發者不想犧牲 Serial 的 debug 訊息以及設計額外電路處理 Serial1 bootstrapping 設定時,使用 SoftwareSerial 即可方便快速地產生另一組 Serial (UART) 埠供連接裝置使用。

實作細節

SoftwareSerial 函式庫是基於 Arduino 的 SoftwareSerial 函式庫所開發,並將其中與硬體相關的暫存器讀寫操作替換為標準 Arduino GPIO 和 EINT 的 API 呼叫。雖然這會增加一些系統運作上的負載,但由於 MT7697 SoC 的快取機制以及高於一般 Arduino 開發板的 CPU 運作時脈,SoftwareSerial 函式庫仍可以支援至 115,200 的 UART 傳輸 baud rate。若開發者對進一步加速此函式庫的實作有興趣,可參考 GitHub 上,瞭解如何使用 MT7697 暫存器操作來實現 GPIO 功能。

相關討論