Skip to content

Latest commit

 

History

History
98 lines (80 loc) · 3.45 KB

UART.md

File metadata and controls

98 lines (80 loc) · 3.45 KB
layout title permalink
code
Writing to UART
/UART.htm

Writing to UART

Learn how to use HardwareSerial to read and write to the UART port.

Info on using UART and HardwareSerial

  • HardwareSerial defines an object called Serial1.
    • This reads and writes to COM2 on the Windows Image which is linked to the UART port on the Galileo board.
  • To use serialEvent1() you’ll need to edit the project settings
    • Right click on the Project in the Solution Explorer, then select Properties.
    • Under Configuration Properties -> C/C++ -> Preprocessor, add SERIAL_EVENT1; to Preprocessor Definitions.

Required Components

Allow UART to be used for HardwareSerial (This will change it from kernel debugger use)

  1. Shut down Galileo and remove power
  2. Remove microSD card and plug it in to a PC (Windows will automatically assign a drive letter, in our case it was "k")
  3. Open an Administrative command prompt on your development machine:
    • bcdedit /store k:\efi\microsoft\boot\bcd /enum
    • Verify you got bcd contents
    • bcdedit /store k:\efi\microsoft\boot\bcd /set {default} debug No
    • bcdedit /store c:\efi\microsoft\boot\bcd /set {default} testsigning OFF
    • bcdedit /store k:\efi\microsoft\boot\bcd /enum
    • Verify debug and testsigning are now “No”
  4. Safe dismount of microSD from PC by ejecting in Windows Explorer.
  5. Put microSD in Galileo and powered up

Create a new project

  1. Create a new project from the template.
  2. Plug the two serial ends of the cables together.
  3. Plug the 3.5mm end of the cable into the UART jack on the Galileo board.
  4. Plug the USB end of the cable into your computer's USB port.
  5. Open up Device Manager on your development machine and find out which COM port is being used by the adapter.
  6. Open a terminal program like Tera Term{:target="_blank"}
  7. Set the program to monitor the serial connection from the COM port you found in Step 5.
  8. Make sure your options are as shown below (with the Port set to the COM port you found in Step 5):

    • If you are using Tera Term, you can get to the menu shown above by clicking on Setup -> Serial port..
  9. Replace the existing code in main.cpp with the following code:

Code

Main.cpp

{% highlight C++ %} #include "stdafx.h" #include "arduino.h"

int _tmain(int argc, _TCHAR* argv[]) { return RunArduinoSketch(); }

void setup() { Serial1.begin(CBR_9600, Serial.SERIAL_8N1); }

char output = 'a'; // The character being written

void loop() { // Handles the writing if (Serial1.write(output) != 1) { Log(L"Serial1.write failed\n"); } else { Log(L"%c being sent\n", output); }

// Loops the character from a to z
if (output == 'z')
{
    output = 'a';
}
else
{
    output++;
}

Sleep(1000);

} {% endhighlight %}


« Return to Samples{:role="button"}{:class="btn btn-default"}