User Tools

Site Tools

한국어

moacon:opencom:index

openCom

void openCom (u8 comCh, u32 comBaud, u8 comMode)

comCh : Channel number
comBaud : Baud rate
comMode: Communication mode (data bits, parity, and stop bits)

Opens the port on channel comCh with the given baud rate, comBaud, and the communication mode, comMode.

comBaud is the baud rate. It can be set to any value between 300 and 115200, but generally it is set to one of the following values.

   1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 76800, 115200

comMode sets the number of data bits, stop bits, and parity for the port. Several constants have been predefined to make this argument easier to set and understand. They are shown in the table below.

comMode Data bits Parity Stop Bits
C7E17EVEN1
C7O17ODD1
C8N18NO1
C8E18EVEN1
C8O18ODD1
C7E27EVEN2
C7O27ODD2
C8N28NO2
C8E28EVEN2
C8O28ODD2

openCom clears and allocates 255 bytes for the receive buffer. The receive buffer's size cannot be set by the user.

The following is a sample programming demonstrating the use of openCom.

#include "moacon500.h"
void cmain(void)
{
 openCom(0, 115200, C8N1);         // Channel 0, 115200 Baud, data bits: 8, no parity, stop bits: 1
 while (1)                         // Repeat forever
 {
    delay(500);                    // Wait for 500ms
    comPrint(0,"abc\r\n");         // transmits "abc" and a new line
    comPut(0,0x41);                // transmits the letter 'A' (ASCII 0x41)
 }
}

Connect a PC to MOACON's RS-232 channel 0 and use HyperTerminal to view the output.

go MOACON home

moacon/opencom/index.txt · Last modified: 2016/04/14 11:07 (external edit)