Difference between revisions of "ARDUINO MEGA Functions Serial Link"

From ROBOTC API Guide
Jump to: navigation, search
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<yambe:breadcrumb>ARDUINO_MEGA_Functions_and_Variables|Functions and Variables</yambe:breadcrumb>
+
{{DISPLAYTITLE:2560 (MEGA) Serial Link Functions}}
 +
<yambe:breadcrumb self="2560 (MEGA) Serial Link">ARDUINO_MEGA_Functions_and_Variables|Functions and Variables</yambe:breadcrumb>
 
<br />
 
<br />
The Arduino MEGA has 4 user serial ports - 1 reversed for the system and 3 user controllable serial ports. These serial ports can be configured in code or via the Motors and Sensor Setup window. The serial ports are buffered as well, with a 70 byte receive buffer and a 40 byte transmit buffer.
+
 
 +
The Arduino MEGA has 4 user serial ports - 1 reversed for the system and 3 user controllable serial ports. These serial ports can be configured in code or via the Motors and Sensor Setup window. The serial ports are buffered - a 70 byte receive buffer and a 40 byte transmit buffer.
  
 
[[File:SerialPortsMega.png]]
 
[[File:SerialPortsMega.png]]
Line 110: Line 112:
 
<br />
 
<br />
  
== sendChar ==  
+
== configureSerialPort ==  
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| class="functionType"| <span class="bigKeywordBI">void </span><span class="bigKeywordB">sendChar</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const </span><span class="bigKeywordB">TUARTs </span><span class="bigCodeBasic">nPort</span><span class="bigCodePunc">, </span><span class="bigKeywordBI">short </span><span class="bigCodeBasic">nChar</span><span class="bigCodePunc">)</span>
+
| class="functionType"| <span class="bigKeywordBI">void </span><span class="bigKeywordB">configureSerialPort</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const </span><span class="bigKeywordB">TUARTs </span><span class="bigCodeBasic">nPort</span><span class="bigCodePunc">, </span><span class="bigKeywordBI">TSerialPortMode </span><span class="bigCodeBasic">nMode</span><span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) Function will send the next character to port 'nPort'.  
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) This function will manually configure the serial port for a specific mode (system, user, Xbee, VEX LCD, etc). You can also set this same functionality using the "Motors and Sensor Setup" window.
 
+
<br />
  
 
{| class="parameterTable" cellpadding="5%" width="100%"
 
{| class="parameterTable" cellpadding="5%" width="100%"
Line 127: Line 129:
 
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_TUARTs|TUARTs]]
 
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_TUARTs|TUARTs]]
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''nChar''  
+
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''TSerialPortMode''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|A char to send to 'nPort'. (Can be a short or a char)
+
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The type of the serial device attached to this pin.
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|[[Data_Types#dataType_short|short]]
+
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|[[Data_Types#dataType_TSerialPortMode|TSerialPortMode]]
 
   |-
 
   |-
 
   |}
 
   |}
Line 137: Line 139:
 
   |-
 
   |-
 
   |<syntaxhighlight lang="robotc">
 
   |<syntaxhighlight lang="robotc">
sendChar(uartOne, 'B');  // send the next char from UART Port 'uartOne'
+
configureSerialPort(UART1, uartUserControl);  //Configures UART1 as a User Control Serial Port
 
</syntaxhighlight>
 
</syntaxhighlight>
 
   |-
 
   |-
Line 145: Line 147:
 
<br />
 
<br />
  
== setBaudRate ==
+
== bXmitComplete ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| class="functionType"| <span class="bigKeywordBI">void </span><span class="bigKeywordB">setBaudRate</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const </span><span class="bigKeywordB">TUARTs </span><span class="bigCodeBasic">nPort</span><span class="bigCodePunc">, </span><span class="bigKeywordB">TBaudRate </span><span class="bigCodeBasic">nBaudRate</span><span class="bigCodePunc">)</span>
+
| class="functionType"| <span class="bigKeywordBI">bool </span><span class="bigKeywordB">bXmitComplete</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const </span><span class="bigKeywordB">TUARTs </span><span class="bigCodeBasic">nPort</span><span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]])  Function will set the Baud Rate for port 'nPort'.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_bool|bool]])  Function will return if the transmit (Xmit) buffer is empty.
Acceptable Baud Rates: 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 200000, 230400 and 250000.  
+
  
  
Line 162: Line 163:
 
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|A sensor port or name
 
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|A sensor port or name
 
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_TUARTs|TUARTs]]
 
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_TUARTs|TUARTs]]
  |-
 
  | style="border-style: solid; border-width: 0px 0px 0px 0px"|''nBaudRate''
 
  | style="border-style: solid; border-width: 0px 0px 0px 0px"|The baud rate to use
 
  | style="border-style: solid; border-width: 0px 0px 0px 0px"|[[Data_Types#dataType_TBaudRate|TBaudRate]]
 
 
   |-
 
   |-
 
   |}
 
   |}
Line 173: Line 170:
 
   |-
 
   |-
 
   |<syntaxhighlight lang="robotc">
 
   |<syntaxhighlight lang="robotc">
setBaudRate(uartOne, baudRate9600);  // retrieve the next char from UART Port 'uartOne'
+
  sendChar(UART1, 'H');     //Send a character
 +
  if(!bXmitComplete(UART0)) //Wait until character has been transmitted
 +
    wait1Msec(1);
 
</syntaxhighlight>
 
</syntaxhighlight>
 
   |-
 
   |-

Latest revision as of 20:54, 11 May 2012

ARDUINOFunctions and Variables → 2560 (MEGA) Serial Link


The Arduino MEGA has 4 user serial ports - 1 reversed for the system and 3 user controllable serial ports. These serial ports can be configured in code or via the Motors and Sensor Setup window. The serial ports are buffered - a 70 byte receive buffer and a 40 byte transmit buffer.

SerialPortsMega.png

Color Key
Function:
Variable:


getChar

short getChar(const TUARTs nPort)
(short) Function will retrieve the next character from the buffer that was sent to port 'nPort'.


Parameter Explanation Data Type
nPort A sensor port or name TUARTs


getChar(uartOne);  // retrieve the next char from UART Port 'uartOne'


sendChar

void sendChar(const TUARTs nPort, short nChar)
(void) Function will send the next character to port 'nPort'.


Parameter Explanation Data Type
nPort A sensor port or name TUARTs
nChar A char to send to 'nPort'. (Can be a short or a char) short


sendChar(uartOne, 'B');  // send the next char from UART Port 'uartOne'


setBaudRate

void setBaudRate(const TUARTs nPort, TBaudRate nBaudRate)
(void) Function will set the Baud Rate for port 'nPort'.

Acceptable Baud Rates: 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 200000, 230400 and 250000.


Parameter Explanation Data Type
nPort A sensor port or name TUARTs
nBaudRate The baud rate to use TBaudRate


setBaudRate(uartOne, baudRate9600);  // retrieve the next char from UART Port 'uartOne'


configureSerialPort

void configureSerialPort(const TUARTs nPort, TSerialPortMode nMode)
(void) This function will manually configure the serial port for a specific mode (system, user, Xbee, VEX LCD, etc). You can also set this same functionality using the "Motors and Sensor Setup" window.


Parameter Explanation Data Type
nPort A sensor port or name TUARTs
TSerialPortMode The type of the serial device attached to this pin. TSerialPortMode


configureSerialPort(UART1, uartUserControl);  //Configures UART1 as a User Control Serial Port


bXmitComplete

bool bXmitComplete(const TUARTs nPort)
(bool) Function will return if the transmit (Xmit) buffer is empty.


Parameter Explanation Data Type
nPort A sensor port or name TUARTs


  sendChar(UART1, 'H');      //Send a character
  if(!bXmitComplete(UART0))  //Wait until character has been transmitted
    wait1Msec(1);