#include "stm32f1xx_ll_adc.h" #include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_rcc.h" #include "math.h" void accelero_init(void){ RCC -> CFGR |= (0x1<<15); RCC-> CFGR &= ~ (0x1<<14); LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1); LL_ADC_REG_InitTypeDef adc; adc.TriggerSource = LL_ADC_REG_TRIG_SOFTWARE ; adc.SequencerLength = LL_ADC_REG_SEQ_SCAN_DISABLE; adc.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_1RANK; adc.ContinuousMode = LL_ADC_REG_CONV_SINGLE; adc.DMATransfer = LL_ADC_REG_DMA_TRANSFER_NONE; LL_ADC_REG_Init(ADC1, &adc); LL_ADC_Enable(ADC1); } int accelero_roulis(void){ int x=0; int y=0; int angle; LL_ADC_SetAnalogWDMonitChannels(ADC1, LL_ADC_AWD_CHANNEL_10_REG); LL_ADC_REG_StartConversionSWStart(ADC1); while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1){ //__asm__"nope"; } x = LL_ADC_REG_ReadConversionData32(ADC1); LL_ADC_SetAnalogWDMonitChannels(ADC1, LL_ADC_AWD_CHANNEL_11_REG); while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1){ //__asm__"nope"; } y = LL_ADC_REG_ReadConversionData32(ADC1); angle = atan(x/y); if (angle>40.0) { return 1; }else { return 0; } //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 }