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 |
---|---|---|---|
C7E1 | 7 | EVEN | 1 |
C7O1 | 7 | ODD | 1 |
C8N1 | 8 | NO | 1 |
C8E1 | 8 | EVEN | 1 |
C8O1 | 8 | ODD | 1 |
C7E2 | 7 | EVEN | 2 |
C7O2 | 7 | ODD | 2 |
C8N2 | 8 | NO | 2 |
C8E2 | 8 | EVEN | 2 |
C8O2 | 8 | ODD | 2 |
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.