/*
*
* Keil project
gia to LIS302DL h to LIS3DSH accelerometer sto STM32F4-Discovery board
*
*
* @ide Keil uVision 5
* @packs STM32F4xx Keil
packs version 2.2.0 or greater required
* @stdperiph STM32F4xx Standard peripheral drivers version
1.4.0 or greater required
*
* Sthn energopoihsh, an to STM32F4-Discovery board exei to accelerometer LIS302DL,
* ta LED_GREEN kai
LED_RED tha anapsoun gia 2 deuterolepta,
* An exei to
accelerometer LIS3DSH ,
* ta LED_BLUE kai
LED_ORANGE tha anapsoun gia 2 deuterolepta.
*
* An anapsoun ola ta led mazi,shmainei
pws uparxei kapoio error.
*/
/* Eisagwgh
kuriwn modules */
#include
"stm32f4xx.h"
/* Eisagwgh
biblithikwn */
#include "defines.h"
#include
"tm_stm32f4_disco.h"
#include
"tm_stm32f4_delay.h"
#include
"tm_stm32f4_lis302dl_lis3dsh.h"
/* Dedomena
gia to Accelerometer */
TM_LIS302DL_LIS3DSH_t Axes_Data;
int main(void) {
/* Energopoihsh susthmatos
*/
SystemInit();
/* Energopoihsh tou
delay */
TM_DELAY_Init();
/* Energopoihsh twn
LEDs */
TM_DISCO_LedInit();
/* Entopise thn katallhlh suskeuh */
if (TM_LIS302DL_LIS3DSH_Detect() ==
TM_LIS302DL_LIS3DSH_Device_LIS302DL) {
/* Anapse ta GREEN kai RED */
TM_DISCO_LedOn(LED_GREEN | LED_RED);
/* Energopoihse to LIS302DL */
TM_LIS302DL_LIS3DSH_Init(TM_LIS302DL_Sensitivity_2_3G,
TM_LIS302DL_Filter_2Hz);
} else if (TM_LIS302DL_LIS3DSH_Detect() == TM_LIS302DL_LIS3DSH_Device_LIS3DSH) {
/* Alliws anapse ta
BLUE kai ORANGE */
TM_DISCO_LedOn(LED_BLUE | LED_ORANGE);
/* Energopoihse to LIS3DSH */
TM_LIS302DL_LIS3DSH_Init(TM_LIS3DSH_Sensitivity_2G,
TM_LIS3DSH_Filter_800Hz);
} else {
/* Alliws,h suskeuh den anagnwrizetai */
/* Anapse ola
ta leds */
TM_DISCO_LedOn(LED_GREEN | LED_RED | LED_BLUE | LED_ORANGE);
/* Atermwn broxos */
while (1);
}
/* Delay gia 2 deuterolepta
*/
Delayms(2000);
TM_DISCO_LedOff(LED_ALL);
while (1) {
/* Anagnwsh twn dedomenwn stous aksones tou accelerometer */
TM_LIS302DL_LIS3DSH_ReadAxes(&Axes_Data);
/* Elegxos tou X aksona.
An einai
pros ta deksia tote tha anavoun deksiostrofa*/
if (Axes_Data.X > 200) {
TM_DISCO_LedOn(LED_RED);
TM_DISCO_LedOff(LED_ORANGE);
/* Elegxos tou Y aksona.
Analoga
me th thesi
tou board auksanetai h meiwnetai h taxuthta diadoxhs twn leds*/
if (Axes_Data.Y > 200){ Delayms(200);}
else if (Axes_Data.Y < -200) {
Delayms(800);}
else{
Delayms(500);}
TM_DISCO_LedOn(LED_BLUE);
TM_DISCO_LedOff(LED_RED);
if (Axes_Data.Y > 200){ Delayms(200);}
else if (Axes_Data.Y < -200) {
Delayms(800);}
else{
Delayms(500);}
TM_DISCO_LedOn(LED_GREEN);
TM_DISCO_LedOff(LED_BLUE);
if (Axes_Data.Y > 200){ Delayms(200);}
else if (Axes_Data.Y < -200) {
Delayms(800);}
else{
Delayms(500);}
TM_DISCO_LedOn(LED_ORANGE);
TM_DISCO_LedOff(LED_GREEN);
if (Axes_Data.Y > 200){ Delayms(200);}
else if (Axes_Data.Y < -200) {
Delayms(800);}
else{
Delayms(500);}
}
/* Elegxos tou X aksona.
An einai
pros ta aristera tote tha anavoun aristerostrofa*/
if (Axes_Data.X < -200) {
TM_DISCO_LedOn(LED_RED);
TM_DISCO_LedOff(LED_BLUE);
/* Elegxos tou Y aksona.
Analoga
me th thesi
tou board auksanetai h meiwnetai h taxuthta diadoxhs twn leds*/
if (Axes_Data.Y > 200){ Delayms(200);}
else if (Axes_Data.Y < -200) {
Delayms(800);}
else{
Delayms(500);}
TM_DISCO_LedOn(LED_ORANGE);
TM_DISCO_LedOff(LED_RED);
if (Axes_Data.Y > 200){ Delayms(200);}
else if (Axes_Data.Y < -200) {
Delayms(800);}
else{
Delayms(500);}
TM_DISCO_LedOn(LED_GREEN);
TM_DISCO_LedOff(LED_ORANGE);
if (Axes_Data.Y > 200){ Delayms(200);}
else if (Axes_Data.Y < -200) {
Delayms(800);}
else{
Delayms(500);}
TM_DISCO_LedOn(LED_BLUE);
TM_DISCO_LedOff(LED_GREEN);
if (Axes_Data.Y > 200){ Delayms(200);}
else if (Axes_Data.Y < -200) {
Delayms(800);}
else{
Delayms(500);}
}
/* Otan den metakinoume
to board,ta leds na paremenoun
svhsta*/
TM_DISCO_LedOff(LED_ALL);
}
}
Στο βίντεο φαίνεται η λειτουργία της πλακέτας με τον παραπάνω κώδικα.
Η εικόνα στο πρόγραμμα Labview όπου έχει οπτικοποιηθεί η πλακέτα stm32f4g είναι η εξής.
Στο πρόγραμμα Labview η εικόνα του block diagramm θα είναι η εξής.
Υπάρχει και η δυνατότητα λήψης του αρχείου του προγράμματος Labview από τον παρακάτω σύνδεσμο.