"merged" accelerometer and emmeteur hf
This commit is contained in:
parent
69cbefea01
commit
a8458eeacf
4 changed files with 177 additions and 0 deletions
83
keil_project/Services/accelerometer.c
Normal file
83
keil_project/Services/accelerometer.c
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
#include "accelerometer.h"
|
||||||
|
double x;
|
||||||
|
double y;
|
||||||
|
double angle;
|
||||||
|
|
||||||
|
void accelero_init(void){
|
||||||
|
RCC -> CFGR |= (0x1<<15);
|
||||||
|
RCC-> CFGR &= ~ (0x1<<14);
|
||||||
|
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1);
|
||||||
|
LL_APB1_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC);
|
||||||
|
|
||||||
|
LL_GPIO_InitTypeDef pc0, pc1;
|
||||||
|
LL_ADC_InitTypeDef adc;
|
||||||
|
LL_ADC_REG_InitTypeDef adcReg;
|
||||||
|
|
||||||
|
pc0.Pin = LL_GPIO_PIN_0;
|
||||||
|
pc0.Mode = LL_GPIO_MODE_ANALOG;
|
||||||
|
pc1.Pin = LL_GPIO_PIN_1;
|
||||||
|
pc1.Mode = LL_GPIO_MODE_ANALOG;
|
||||||
|
|
||||||
|
|
||||||
|
adc.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT;
|
||||||
|
adc.SequencersScanMode = LL_ADC_SEQ_SCAN_DISABLE;
|
||||||
|
LL_ADC_Init(ADC1, &adc);
|
||||||
|
|
||||||
|
adcReg.TriggerSource = LL_ADC_REG_TRIG_SOFTWARE ;
|
||||||
|
adcReg.SequencerLength = LL_ADC_REG_SEQ_SCAN_DISABLE;
|
||||||
|
adcReg.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE;
|
||||||
|
adcReg.ContinuousMode = LL_ADC_REG_CONV_SINGLE;
|
||||||
|
adcReg.DMATransfer = LL_ADC_REG_DMA_TRANSFER_NONE;
|
||||||
|
|
||||||
|
|
||||||
|
LL_ADC_REG_Init(ADC1, &adcReg);
|
||||||
|
|
||||||
|
/*LL_ADC_SetChannelSamplingTime(ADC2, LL_ADC_CHANNEL_10, LL_ADC_SAMPLINGTIME_1CYCLE_5);
|
||||||
|
LL_ADC_SetChannelSamplingTime(ADC2, LL_ADC_CHANNEL_11, LL_ADC_SAMPLINGTIME_1CYCLE_5);
|
||||||
|
*/
|
||||||
|
|
||||||
|
LL_ADC_Enable(ADC1);
|
||||||
|
|
||||||
|
//LL_ADC_EnableIT_EOS(ADC1);
|
||||||
|
//wait 0,2 µs, calibration is advised
|
||||||
|
//LL_ADC_StartCalibration(ADC1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double accelero_get_x(void){
|
||||||
|
LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_10);
|
||||||
|
LL_ADC_REG_StartConversionSWStart(ADC1);
|
||||||
|
while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1){
|
||||||
|
//__asm__"nope";
|
||||||
|
}
|
||||||
|
double x= LL_ADC_REG_ReadConversionData12(ADC1);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
double accelero_get_y(void){
|
||||||
|
LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_11);
|
||||||
|
LL_ADC_REG_StartConversionSWStart(ADC1);
|
||||||
|
while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1){
|
||||||
|
//__asm__"nope";
|
||||||
|
}
|
||||||
|
double y = LL_ADC_REG_ReadConversionData12(ADC1);
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int accelero_angle_bon(void){
|
||||||
|
x = accelero_get_x();
|
||||||
|
y = accelero_get_y();
|
||||||
|
angle = x/y;
|
||||||
|
|
||||||
|
if (angle>tan(0.698132)){
|
||||||
|
return 0;
|
||||||
|
}else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//le flag EOC n'est jamais mis à un ....
|
||||||
|
// Soit la conversion est mal faite soit on n'utilise pas bien la simulation
|
||||||
|
//soit on n'utilise pas bien isActiveFlag dans la boucle
|
||||||
|
}
|
||||||
|
|
28
keil_project/Services/accelerometer.h
Normal file
28
keil_project/Services/accelerometer.h
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// RIEN A MODIFIER //
|
||||||
|
|
||||||
|
#ifndef ACCELERO_H
|
||||||
|
#define ACCELERO_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "stm32f103xb.h"
|
||||||
|
#include "stm32f1xx_ll_adc.h"
|
||||||
|
#include "stm32f1xx_ll_bus.h"
|
||||||
|
#include "stm32f1xx_ll_rcc.h"
|
||||||
|
#include "stm32f1xx_ll_gpio.h"
|
||||||
|
#include "math.h"
|
||||||
|
|
||||||
|
/* =====================================================================================
|
||||||
|
Les fonctions qui gèrent les IO (ajout par rapport à l'activité 1)
|
||||||
|
=======================================================================================*/
|
||||||
|
|
||||||
|
void accelero_init(void);
|
||||||
|
|
||||||
|
double accelero_get_x(void);
|
||||||
|
|
||||||
|
double accelero_get_y(void);
|
||||||
|
|
||||||
|
int accelero_angle_bon(void);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
52
keil_project/Services/emetteur_rf.c
Normal file
52
keil_project/Services/emetteur_rf.c
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
#include "emetteur_rf.h"
|
||||||
|
|
||||||
|
void emetteur_rf_init(void){
|
||||||
|
|
||||||
|
LL_USART_InitTypeDef My_LL_Usart_Init_Struct;
|
||||||
|
|
||||||
|
|
||||||
|
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
|
||||||
|
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
|
||||||
|
LL_GPIO_InitTypeDef tx;
|
||||||
|
tx.Mode = LL_GPIO_MODE_ALTERNATE;
|
||||||
|
tx.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||||
|
tx.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||||
|
tx.Pin = LL_GPIO_PIN_9;
|
||||||
|
LL_GPIO_Init(GPIOA, &tx);
|
||||||
|
|
||||||
|
LL_GPIO_InitTypeDef pa11_init_conf;
|
||||||
|
pa11_init_conf.Mode = LL_GPIO_MODE_OUTPUT;
|
||||||
|
pa11_init_conf.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||||
|
pa11_init_conf.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||||
|
pa11_init_conf.Pin = LL_GPIO_PIN_11;
|
||||||
|
LL_GPIO_Init(GPIOA, &pa11_init_conf);
|
||||||
|
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
|
||||||
|
|
||||||
|
|
||||||
|
My_LL_Usart_Init_Struct.BaudRate = 9600;
|
||||||
|
My_LL_Usart_Init_Struct.DataWidth = LL_USART_DATAWIDTH_8B ;
|
||||||
|
My_LL_Usart_Init_Struct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
|
||||||
|
My_LL_Usart_Init_Struct.OverSampling = LL_USART_OVERSAMPLING_16;
|
||||||
|
My_LL_Usart_Init_Struct.Parity = LL_USART_PARITY_NONE;
|
||||||
|
My_LL_Usart_Init_Struct.StopBits = LL_USART_STOPBITS_1;
|
||||||
|
My_LL_Usart_Init_Struct.TransferDirection = LL_USART_DIRECTION_TX_RX ;
|
||||||
|
|
||||||
|
LL_USART_Init(USART1,&My_LL_Usart_Init_Struct);
|
||||||
|
LL_USART_Enable(USART1);
|
||||||
|
|
||||||
|
/*int periph_speed;
|
||||||
|
if (uart_port==USART1) periph_speed = 36000000;
|
||||||
|
if (uart_port==USART2) periph_speed = 72000000;
|
||||||
|
if (uart_port==USART3) periph_speed = 72000000;
|
||||||
|
|
||||||
|
LL_USART_SetBaudRate(uart_port, periph_speed, baudrate);
|
||||||
|
*/}
|
||||||
|
|
||||||
|
void emetteur_send_bytes(USART_TypeDef * uart_port,char* buf, int len){
|
||||||
|
for(int i = 0; i < len; i++){
|
||||||
|
LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_11);
|
||||||
|
LL_USART_TransmitData8(uart_port, buf[i]);
|
||||||
|
while(!LL_USART_IsActiveFlag_TXE(uart_port));
|
||||||
|
LL_GPIO_ResetOutputPin(GPIOA,LL_GPIO_PIN_11);
|
||||||
|
}
|
||||||
|
}
|
14
keil_project/Services/emetteur_rf.h
Normal file
14
keil_project/Services/emetteur_rf.h
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef RECEPTEURHF_INPUT_H
|
||||||
|
#define RECEPTEURHF_INPUT_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "stm32f1xx_ll_bus.h"
|
||||||
|
#include "stm32f1xx_ll_usart.h"
|
||||||
|
#include "stm32f1xx_ll_gpio.h"
|
||||||
|
|
||||||
|
void emetteur_rf_init();
|
||||||
|
void emetteur_send_bytes(USART_TypeDef * uart_port,char* buf, int len);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue