Validation du fonctionnement de l'ADC1

This commit is contained in:
Manon Sanchez 2023-03-27 16:39:42 +02:00
parent 73141578cd
commit 26e44a6d5b
5 changed files with 194 additions and 24 deletions

1
.gitignore vendored
View file

@ -27,4 +27,3 @@

View file

@ -1,16 +1,34 @@
#include "Driver_ADC.h"
#include "stm32f10x.h" #include "stm32f10x.h"
#include "stdio.h" #include "stdio.h"
#include "Driver_ADC.h"
void init_adc1 (void) void erreur (void)
{ {
while(1);
}
void (*ADC1_2_fx) (void) = &erreur;
/**
*************************************************************************************************
* @brief Activation et configuration de l'ADC1.
* @param -> Priorité de l'intérruption.
* @Note -> Fonction à lancer systématiquement avant daller plus en détail dans les conf plus fines (PWM, codeur inc...)
*************************************************************************************************
*/
void driver_adc_1_init (char Prio, void (*IT_function)(void))
{
//On règle la fréquence à 12Mhz
RCC->CFGR |= RCC_CFGR_ADCPRE_DIV6;
//Validation de l'horloge ACD1
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;
//Activation de l'external trig //Activation de l'external trig
ADC1->CR2 |= ADC_CR2_EXTTRIG; ADC1->CR2 |= ADC_CR2_EXTTRIG;
//Activation SWSTART //Activation SWSTART
ADC1->CR2 |= ADC_CR2_EXTSEL; ADC1->CR2 |= ADC_CR2_EXTSEL;
//On règle la fréquence à 12Mhz //Validation de l'horloge ACD1
RCC->CFGR |= RCC_CFGR_ADCPRE_DIV6; RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;
//Activation de l'ADC //Activation de l'ADC1
ADC1->CR2 |= ADC_CR2_ADON; ADC1->CR2 |= ADC_CR2_ADON;
//Fixe le nb de conversion, ici 1 //Fixe le nb de conversion, ici 1
ADC1->SQR1 &= ADC_SQR1_L; ADC1->SQR1 &= ADC_SQR1_L;
@ -22,18 +40,28 @@ void init_adc1 (void)
while((ADC1->CR2 & ADC_CR2_CAL)); while((ADC1->CR2 & ADC_CR2_CAL));
//Activation de l'intéruption sur le flag EOC //Activation de l'intéruption sur le flag EOC
ADC1->CR1 |= ADC_CR1_EOCIE; ADC1->CR1 |= ADC_CR1_EOCIE;
//Activation de l'intéruption et configuration du niveau de priorité
NVIC_EnableIRQ(ADC1_2_IRQn);
NVIC_SetPriority(ADC1_2_IRQn, Prio);
//Fonction à appeler à l'intéruption
ADC1_2_fx = IT_function;
} }
void launch_read_adc1 (void) void driver_adc_1_launch_read (void)
{ {
//Lancement de la conversion //Lancement de la conversion
ADC1->CR2 |= ADC_CR2_SWSTART; ADC1->CR2 |= ADC_CR2_SWSTART;
} }
int read_adc1 (void) uint16_t driver_adc_1_read (void)
{ {
//On abaisse le flag pour la prochaine lecture
ADC1->SR &= ~ADC_SR_EOC;
//Retour de la conversion //Retour de la conversion
return ADC1->DR &~ ((0x0F) << 12); return ADC1->DR &~ ((0x0F) << 12);
} }
void ADC1_2_IRQHandler(void)
{
//On abaisse le flag pour la prochaine lecture
ADC1->SR &= ~ADC_SR_EOC;
//On lance la fonction de l'utilisateur
(*ADC1_2_fx)();
}

View file

@ -2,8 +2,8 @@
#define DRIVER_ADC_H #define DRIVER_ADC_H
#include "stm32f10x.h" #include "stm32f10x.h"
void init_adc1 (void); void driver_adc_1_init (char Prio, void (*IT_function)(void));
void launch_read_adc1 (void); void driver_adc_1_launch_read (void);
int read_adc1 (void); uint16_t driver_adc_1_read (void);
#endif #endif

View file

@ -26,7 +26,7 @@
<ToolsetNumber>0x4</ToolsetNumber> <ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName> <ToolsetName>ARM-ADS</ToolsetName>
<TargetOption> <TargetOption>
<CLKADS>12000000</CLKADS> <CLKADS>8000000</CLKADS>
<OPTTT> <OPTTT>
<gFlags>1</gFlags> <gFlags>1</gFlags>
<BeepAtEnd>1</BeepAtEnd> <BeepAtEnd>1</BeepAtEnd>
@ -79,8 +79,8 @@
</OPTFL> </OPTFL>
<CpuCode>18</CpuCode> <CpuCode>18</CpuCode>
<DebugOpt> <DebugOpt>
<uSim>0</uSim> <uSim>1</uSim>
<uTrg>1</uTrg> <uTrg>0</uTrg>
<sLdApp>1</sLdApp> <sLdApp>1</sLdApp>
<sGomain>1</sGomain> <sGomain>1</sGomain>
<sRbreak>1</sRbreak> <sRbreak>1</sRbreak>
@ -117,25 +117,96 @@
<pMon>BIN\UL2CM3.DLL</pMon> <pMon>BIN\UL2CM3.DLL</pMon>
</DebugOpt> </DebugOpt>
<TargetDriverDllRegistry> <TargetDriverDllRegistry>
<SetRegEntry>
<Number>0</Number>
<Key>ARMRTXEVENTFLAGS</Key>
<Name>-L70 -Z18 -C0 -M0 -T1</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
<Key>DLGDARM</Key>
<Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=75,104,496,531,0)(121=-1,-1,-1,-1,0)(122=75,104,496,531,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=-1,-1,-1,-1,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=1125,344,1728,1095,1)(151=-1,-1,-1,-1,0)</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
<Key>ARMDBGFLAGS</Key>
<Name>-T0</Name>
</SetRegEntry>
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>UL2CM3</Key> <Key>UL2CM3</Key>
<Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128 -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM))</Name> <Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128 -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM))</Name>
</SetRegEntry> </SetRegEntry>
</TargetDriverDllRegistry> </TargetDriverDllRegistry>
<Breakpoint/> <Breakpoint>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>23</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134219356</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>.\src\main.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\projet_voilier\src/main.c\23</Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>9</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134219402</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>.\src\main.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\projet_voilier\src/main.c\9</Expression>
</Bp>
<Bp>
<Number>2</Number>
<Type>0</Type>
<LineNumber>62</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134218310</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>..\driver\Driver_ADC.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\projet_voilier\../driver/Driver_ADC.c\62</Expression>
</Bp>
</Breakpoint>
<WatchWindow1>
<Ww>
<count>0</count>
<WinNumber>1</WinNumber>
<ItemText>val</ItemText>
</Ww>
</WatchWindow1>
<Tracepoint> <Tracepoint>
<THDelay>0</THDelay> <THDelay>0</THDelay>
</Tracepoint> </Tracepoint>
<DebugFlag> <DebugFlag>
<trace>0</trace> <trace>0</trace>
<periodic>1</periodic> <periodic>1</periodic>
<aLwin>0</aLwin> <aLwin>1</aLwin>
<aCover>0</aCover> <aCover>0</aCover>
<aSer1>0</aSer1> <aSer1>0</aSer1>
<aSer2>0</aSer2> <aSer2>0</aSer2>
<aPa>0</aPa> <aPa>0</aPa>
<viewmode>0</viewmode> <viewmode>1</viewmode>
<vrSel>0</vrSel> <vrSel>0</vrSel>
<aSym>0</aSym> <aSym>0</aSym>
<aTbox>0</aTbox> <aTbox>0</aTbox>
@ -181,7 +252,7 @@
<ToolsetNumber>0x4</ToolsetNumber> <ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName> <ToolsetName>ARM-ADS</ToolsetName>
<TargetOption> <TargetOption>
<CLKADS>12000000</CLKADS> <CLKADS>8000000</CLKADS>
<OPTTT> <OPTTT>
<gFlags>1</gFlags> <gFlags>1</gFlags>
<BeepAtEnd>1</BeepAtEnd> <BeepAtEnd>1</BeepAtEnd>
@ -280,7 +351,7 @@
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>DLGTARM</Key> <Key>DLGTARM</Key>
<Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=75,104,496,509,0)(121=-1,-1,-1,-1,0)(122=-1,-1,-1,-1,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=120,153,405,449,0)(130=-1,-1,-1,-1,0)(131=-1,-1,-1,-1,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0)</Name> <Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=75,104,496,509,0)(121=-1,-1,-1,-1,0)(122=-1,-1,-1,-1,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=120,153,405,449,0)(130=-1,-1,-1,-1,0)(131=-1,-1,-1,-1,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=1048,459,1651,1093,1)(151=-1,-1,-1,-1,0)</Name>
</SetRegEntry> </SetRegEntry>
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
@ -303,7 +374,63 @@
<Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128 -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM))</Name> <Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128 -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM))</Name>
</SetRegEntry> </SetRegEntry>
</TargetDriverDllRegistry> </TargetDriverDllRegistry>
<Breakpoint/> <Breakpoint>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>62</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134218062</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>..\driver\Driver_ADC.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\projet_voilier_reel\../driver/Driver_ADC.c\62</Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>27</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134219156</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>.\src\main.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\projet_voilier_reel\src/main.c\27</Expression>
</Bp>
<Bp>
<Number>2</Number>
<Type>0</Type>
<LineNumber>64</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>..\driver\Driver_ADC.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
</Breakpoint>
<WatchWindow1>
<Ww>
<count>0</count>
<WinNumber>1</WinNumber>
<ItemText>val</ItemText>
</Ww>
</WatchWindow1>
<Tracepoint> <Tracepoint>
<THDelay>0</THDelay> <THDelay>0</THDelay>
</Tracepoint> </Tracepoint>

View file

@ -2,13 +2,29 @@
#include "Driver_GPIO.h" #include "Driver_GPIO.h"
#include "Driver_Timer.h" #include "Driver_Timer.h"
#include "Driver_ADC.h" #include "Driver_ADC.h"
int main() {
void toto (void)
{
static uint16_t val;
val = driver_adc_1_read();
}
int main() {
MyGPIO_Struct_TypeDef LED; MyGPIO_Struct_TypeDef LED;
MyGPIO_Struct_TypeDef GPIO_ADC1;
LED.GPIO_Pin = 5; LED.GPIO_Pin = 5;
LED.GPIO_Conf = Out_Ppull; LED.GPIO_Conf = Out_Ppull;
LED.GPIO = GPIOA; LED.GPIO = GPIOA;
MyGPIO_Init(&LED); MyGPIO_Init(&LED);
MyGPIO_Set(LED.GPIO, LED.GPIO_Pin); MyGPIO_Set(LED.GPIO, LED.GPIO_Pin);
GPIO_ADC1.GPIO_Pin = 1;
GPIO_ADC1.GPIO_Conf = In_Analog;
GPIO_ADC1.GPIO = GPIOC;
MyGPIO_Init(&GPIO_ADC1);
driver_adc_1_init(0x01,&toto);
driver_adc_1_launch_read();
while(1); while(1);
} }