Setting UART


Before using UART, it needs to set parameters such as baud rate, data bit, stop bit, parity and flowcontrol by using "set" command of pid_ioctl function.

pid_ioctl($pid, "set ITEM VALUE");

ITEM means setting items and VALUE is possible value of the item.

Available UART Items

ITEM VALUE Description Default
Value
baud ex) 9600 baud rate[bps] 19200
parity 0 no parity 0
1 EVEN parity
2 ODD parity
3 MARK parity (always 1)
4 SPACE parity (always 0)
data 8 8 data bit 8
7 7 data bit(it can be only used with parity bit)
stop 1 1 stop bit 1
2 2 stop bit
flowctrl 0 no flow control 0
1 RTS/CTS hardware flow control
2 Xon/Xoff software flow control
3 TxDE flow control for RS485

example of setting UART

<?php
$pid = pid_open("/mmap/uart0");    // open UART 0
pid_ioctl($pid, "set baud 9600");  // baud rate: 9600 bps
pid_ioctl($pid, "set parity 0");   // no parity
pid_ioctl($pid, "set data 8");     // data bit length: 8
pid_ioctl($pid, "set stop 1");     // stop bit length: 1
pid_ioctl($pid, "set flowctrl 0"); // no flow control
?>