1 /* (CC-BY-NC-SA) ROBIN KRENS - ROBIN @ ROBINKRENS.NL
4 * 2019/9/14 - ROBIN KRENS
18 #include <sys/robsys.h>
20 #include <lib/regfunc.h>
21 #include <lib/string.h>
22 #include <lib/tinyprintf.h>
24 #include <drivers/st7735s.h>
29 /* Peripherial init */
30 rsetbit(RCC_APB1ENR, 14); // enable SPI2
31 rsetbit(RCC_APB2ENR, 3); // enable GPIOB
33 /* The PINS used are respective PB12, PB13 and PB15
34 * NSS (or CS): alternative function pusp-pull
35 * NSS Output is (always high) enabled with this setting
36 * SCK Master: alternate function push-pull
37 * MOSI (or DI): alternate function push-pull */
38 rwrite(GPIOB_CRH, 0xA4AA4444);
40 /* Chip select: software enabled */
44 // LOW and first edge: standard settings
46 rsetbit(SPI2_CR1, 15); // one-wire mode
47 rsetbit(SPI2_CR1, 14); // start with transfer
48 rsetbit(SPI2_CR1, 4); // FPLCK div 8
49 rsetbit(SPI2_CR1, 2); // master selection
50 rsetbit(SPI2_CR1, 6); // enable SPI
63 while (!rchkbit(SPI2_SR, 1));
64 rclrbit(SPI2_CR1, 14); // receive