Write "Hello world!" out via SPI protocol and receive an echo
cmake_minimum_required(VERSION 3.12)
project(SPI_Demo)
create_simple_executable(${PROJECT_NAME} SPI_Demo.cpp)
static const Port::Mask
MOSI = Port::Mask::P0;
static const Port::Mask
MISO = Port::Mask::P1;
static const Port::Mask
SCLK = Port::Mask::P2;
static const Port::Mask
CS = Port::Mask::P6;
static const uint32_t
FREQ = 100000;
static const SPI::Mode
MODE = SPI::Mode::MODE_0;
static const SPI::BitMode
BITMODE = SPI::BitMode::MSB_FIRST;
char string[] = "Hello world!\n";
char *s;
char in;
SPI spi = SPI::get_instance();
Pin cs(
CS, Pin::Dir::OUT);
SimplePort debugLEDs(Port::P16, 8, Pin::Dir::OUT);
while (1) {
while (*s) {
cs.clear();
spi.shift_out(8, (uint32_t) *s);
cs.set();
while (in != *s) {
cs.clear();
in = (
char) spi.shift_in(8);
cs.set();
}
++s;
}
debugLEDs.toggle();
}
}