PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
UARTTX_Demo.cpp

Write "Hello world!" out via UART protocol

cmake_minimum_required(VERSION 3.12)
find_package(PropWare REQUIRED)
project(SimplexUART_Demo C CXX ASM)
create_simple_executable(${PROJECT_NAME} UARTTX_Demo.cpp)
// Includes
static void error (const PropWare::ErrorCode err);
static const int32_t BAUD_RATE = 115200;
static const int32_t DELAY = 200;
int main () {
PropWare::ErrorCode err;
UARTTX uart;
// Create an easy-to-test number pattern - useful when testing with a logic
// analyzer
uint8_t numberPattern[] = {
0x01,
0x02,
0x03,
0x45,
0xe5,
0xaa,
0xff,
0x80,
0x00 }; // Make sure we have a null-terminator for puts
// Create the test string - useful when testing with a terminal
char string[] = "Hello world! This is my most favoritest sentence ever!!!\r\n";
// Typical RS232 settings (default settings for PropGCC serial comms)
uart.set_baud_rate(BAUD_RATE);
if ((err = uart.set_data_width(8)))
error(err);
if ((err = uart.set_stop_bit_width(1)))
error(err);
uart.set_parity(UART::Parity::NO_PARITY);
while (1) {
// Test the number pattern
uart.send_array((char *) numberPattern, sizeof(numberPattern));
waitcnt(DELAY * MILLISECOND + CNT);
// Test a basic string
uart.puts(string);
waitcnt(DELAY * MILLISECOND + CNT);
}
}
void error (const PropWare::ErrorCode err) {
SimplePort debugLEDs(Port::P16, 8, Pin::Dir::OUT);
while (1) {
debugLEDs.write((uint32_t) err);
waitcnt(100*MILLISECOND);
debugLEDs.write(0);
waitcnt(100*MILLISECOND);
}
}
printer.h
PropWare::UART
Abstract base class for all unbuffered UART devices.
Definition: uart.h:86
uarttx.h
PropWare::UARTTX
Definition: uarttx.h:38
PropWare::Pin
Utility class to handle general purpose I/O pins.
Definition: pin.h:36
PropWare::Port
Flexible port that can have any pin enabled or disabled. Pins are independent of each other.
Definition: port.h:38
simpleport.h
main
int main(void)
Definition: GraphicsTest.c:20
PropWare.h
waitcnt
#define waitcnt(a)
Wait until system counter reaches a value.
Definition: propeller.h:176
CNT
#define CNT
The system clock count.
Definition: propeller1.h:151
PropWare::SimplePort
The PropWare::SimplePort is the recommended way to use data ports on the Propeller....
Definition: simpleport.h:36
PropWare
Generic definitions and functions for the Parallax Propeller.
Definition: runnable.h:33