Write "Hello world!" out via UART protocol and receive an echo
cmake_minimum_required(VERSION 3.3)
project(DuplexUART_Demo)
create_simple_executable(${PROJECT_NAME} DuplexUART_Demo.cpp)
const char TEST_STRING[] = "Hello, world!\n";
const uint32_t BAUD_RATE = 115200;
public:
template<size_t N>
: Runnable(stack) {
}
void init ();
private:
char m_buffer[sizeof(TEST_STRING)];
};
void error (const PropWare::ErrorCode err);
uint32_t threadStack[256];
while (1) {
waitcnt(200 * MILLISECOND + CNT);
speaker.
puts(TEST_STRING);
}
}
void error (const PropWare::ErrorCode err) {
while (1) {
debugLEDs.
write((uint32_t) err);
waitcnt(100 * MILLISECOND);
waitcnt(100 * MILLISECOND);
}
}
PropWare::ErrorCode err;
int32_t receivedLength;
this->init();
while (1) {
receivedLength = sizeof(this->m_buffer);
if ((err = this->m_listener.
fgets(this->m_buffer, &receivedLength)))
error(err);
pwSyncOut.
printf(
"Data (%d chars): \"%s\"\n", receivedLength, this->m_buffer);
}
}
void Listener::init () {
memset(m_buffer, 0, sizeof(m_buffer));
waitcnt(10 * MILLISECOND + CNT);
}