aboutsummaryrefslogtreecommitdiffstats
path: root/demos/ARMCM4-STM32F407-DISCOVERY/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'demos/ARMCM4-STM32F407-DISCOVERY/main.c')
-rw-r--r--demos/ARMCM4-STM32F407-DISCOVERY/main.c42
1 files changed, 37 insertions, 5 deletions
diff --git a/demos/ARMCM4-STM32F407-DISCOVERY/main.c b/demos/ARMCM4-STM32F407-DISCOVERY/main.c
index 161bc63b5..d8b72e3f7 100644
--- a/demos/ARMCM4-STM32F407-DISCOVERY/main.c
+++ b/demos/ARMCM4-STM32F407-DISCOVERY/main.c
@@ -21,6 +21,8 @@
#include "ch.h"
#include "hal.h"
#include "test.h"
+#include "lis302dl.h"
+#include "chprintf.h"
static void pwmpcb(PWMDriver *pwmp);
static void adccb(ADCDriver *adcp, adcsample_t *buffer, size_t n);
@@ -78,11 +80,24 @@ static PWMConfig pwmcfg = {
};
/*
- * SPI configuration structure.
- * Maximum speed (12MHz), CPHA=0, CPOL=0, 16bits frames, MSb transmitted first.
- * The slave select line is the pin GPIOA_SPI1NSS on the port GPIOA.
+ * SPI1 configuration structure.
+ * Speed 5.25MHz, CPHA=1, CPOL=1, 8bits frames, MSb transmitted first.
+ * The slave select line is the pin GPIOE_CS_SPI on the port GPIOE.
*/
-static const SPIConfig spicfg = {
+static const SPIConfig spi1cfg = {
+ NULL,
+ /* HW dependent part.*/
+ GPIOE,
+ GPIOE_CS_SPI,
+ SPI_CR1_BR_0 | SPI_CR1_BR_1 | SPI_CR1_CPOL | SPI_CR1_CPHA
+};
+
+/*
+ * SPI2 configuration structure.
+ * Speed 21MHz, CPHA=0, CPOL=0, 16bits frames, MSb transmitted first.
+ * The slave select line is the pin 12 on the port GPIOA.
+ */
+static const SPIConfig spi2cfg = {
spicb,
/* HW dependent part.*/
GPIOB,
@@ -204,7 +219,7 @@ int main(void) {
* PB14 - MISO.
* PB15 - MOSI.
*/
- spiStart(&SPID2, &spicfg);
+ spiStart(&SPID2, &spi2cfg);
palSetPad(GPIOB, 12);
palSetPadMode(GPIOB, 12, PAL_MODE_OUTPUT_PUSHPULL |
PAL_STM32_OSPEED_HIGHEST); /* NSS. */
@@ -235,14 +250,31 @@ int main(void) {
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/*
+ * Initializes the SPI driver 1 in order to access the MEMS. The signals
+ * are initialized in the board file.
+ * Several LIS302DL registers are then initialized.
+ */
+ spiStart(&SPID1, &spi1cfg);
+ lis302dlWriteRegister(&SPID1, LIS302DL_CTRL_REG1, 0x43);
+ lis302dlWriteRegister(&SPID1, LIS302DL_CTRL_REG2, 0x00);
+ lis302dlWriteRegister(&SPID1, LIS302DL_CTRL_REG3, 0x00);
+
+ /*
* Normal main() thread activity, in this demo it does nothing except
* sleeping in a loop and check the button state, when the button is
* pressed the test procedure is launched with output on the serial
* driver 2.
*/
while (TRUE) {
+ uint8_t x, y, z;
+
if (palReadPad(GPIOA, GPIOA_BUTTON))
TestThread(&SD2);
+
+ x = lis302dlReadRegister(&SPID1, LIS302DL_OUTX);
+ y = lis302dlReadRegister(&SPID1, LIS302DL_OUTY);
+ z = lis302dlReadRegister(&SPID1, LIS302DL_OUTZ);
+ chprintf((BaseChannel *)&SD2, "%d, %d, %d\r\n", x, y, z);
chThdSleepMilliseconds(500);
}
}