Printf("%i bytes read : %s\n", rx_length, rx_buffer) An error occured (will occur if there are no bytes) Int rx_length = read(uart0_filestream, (void*)rx_buffer, 255) //Filestream, buffer to store in, number of bytes to read (max) Read up to 255 characters from the port if they are there Write(uart0_filestream, (char*)tx_string.c_str(), tx_string.length()) //Filestream, bytes to write, number of bytes to writeīecause O_NDELAY has been used this will exit if there are no receive bytes waiting (non blocking read), so if you want to hold waiting for input simply put this in a while loop //- CHECK FOR ANY RX BYTES. } Transmit string function uart_tx_string("Hello2") Int count = write(uart0_filestream, &tx_buffer, (p_tx_buffer - &tx_buffer)) //Filestream, bytes to write, number of bytes to write Tcsetattr(uart0_filestream, TCSANOW, &options) Transmitting Bytes //- TX BYTES. Options.c_cflag = B9600 | CS8 | CLOCAL | CREAD //
Using a suitable cable, such as the TTL-232R-3V3-WE, you can connect it to your PC and using some simple terminal software set to 115200-8-N-1 use the command line interface to the Raspberry Pi in the same way as if you we’re using a keyboard and screen connected to it.
If you are running Raspbian or similar then the UART will be used as a serial console.