This is the translation of USB仮想シリアルとUARTの使い方 Version 1. Please check the version of the original documen. The owner may already update the original.
You can use the USB virtual serial in the GR-SAKURA library.
You don't need to use RS232C level conversion circuit board.
Please try to printf for your program debug.
To use USB virtual serial, just do as follows:
Serial.begin(38400);
USB virtual COM port is open by default.
※ Setting Baud rate has no meaning for the USB virtual COM port
In Arduino, Serial.begin has just one argument. But this library supports the second argument.
To use RX63N SCI0 (TxD = P20, RxD =P21), do this:
Serial.begin(38400,SCI_SCI0P2x);
If you want to use SCI1, SCI2, SCI6, do this:
Serial.begin(38400,SCI_SCI1JTAG); // TxD = PF0, RxD =PF2 (shared with JTAG) Serial.begin(38400,SCI_SCI2A); // TxD = P13, RxD =P12 Serial.begin(38400,SCI_SCI2B); // TxD = P50, RxD =P52 (connect to XBEE) Serial.begin(38400,SCI_SCI6A); // TxD = P00, RxD = P01 Serial.begin(38400,SCI_SCI6B); // TxD = P32, RxD = P33
If you omit the second argument, USB virtual COM ports are open.
If you specify SCI_AUTO for the second argument, USB, SCI0, SCI1 are monitored and the channel which receives data first, will be selected.
#include int count; void setup() { Serial.begin(38400); // Open USB virtual COM port pinMode(PIN_LED3, OUTPUT); } void loop() { if(Serial.available()) { // if a data is received Serial.write(Serial.read()); digitalWrite(PIN_LED3, ++count & 1); // flashing } }