forked from trocache/RefKEIL
Added MyADC_Cycle_t, MyADC_Struct_TypeDef and MyADC_Init function.
This commit is contained in:
parent
271f6ee4d7
commit
e9d7d8cc05
5 changed files with 116 additions and 54 deletions
|
@ -1 +1,20 @@
|
|||
#include "adcdriver.h"
|
||||
|
||||
void MyADC_Init(MyADC_Struct_TypeDef * ADCStructPtr)
|
||||
{
|
||||
RCC->CFGR |= RCC_CFGR_ADCPRE_1; // ADC Prescaler : divided by 6 -> 72MHz to 12MHz
|
||||
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; //We activate the clock first
|
||||
if(ADCStructPtr->channel < 10)
|
||||
{
|
||||
ADCStructPtr->ADC->SMPR2 |= (ADCStructPtr->resolution<<(ADCStructPtr->channel*3)); // Cycle and channel selection
|
||||
}
|
||||
else {
|
||||
ADCStructPtr->ADC->SMPR1 |= (ADCStructPtr->resolution<<((ADCStructPtr->channel-10)*3)); // Cycle and channel selection
|
||||
}
|
||||
ADCStructPtr->ADC->SQR3 |= ADCStructPtr->channel; //Sequence Reader, seulement le SQ1 est lu dans notre cas, nous associons un channel à ce dernier.
|
||||
ADCStructPtr->ADC->CR2 |= ADC_CR2_ADON; //ADON Pour l'instant -> PLUS TARD //ADC1->CR2 |= (0x1<<30) //Software start conversion
|
||||
if(ADCStructPtr->isIT)
|
||||
{
|
||||
ADCStructPtr->ADC->CR1 |= ADC_CR1_EOCIE; //Interruption
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,29 @@
|
|||
#ifndef ADCDRIVER_H
|
||||
#define ADCDRIVER_H
|
||||
#include "stm32f10x.h"
|
||||
#include "gpiodriver.h"
|
||||
|
||||
typedef enum{
|
||||
cycles1d5 = 0b000,
|
||||
cycles7d5 = 0b001,
|
||||
cycles13d5 = 0b010,
|
||||
cycles28d5 = 0b011,
|
||||
cycles41d5 = 0b100,
|
||||
cycles55d5 = 0b101,
|
||||
cycles71d5 = 0b110,
|
||||
cycles239d5 = 0b111
|
||||
} MyADC_Cycle_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GPIO_TypeDef * ADC; //ADC 1 or 2
|
||||
ADC_TypeDef * ADC; //ADC 1 or 2
|
||||
uint8_t channel; //channel 0 -> 17
|
||||
MyADC_Cycle_t resolution;
|
||||
char isIT; //true -> interrupt driven
|
||||
} MyADC_Struct_TypeDef;
|
||||
|
||||
void MyADC_Init(MyADC_Struct_TypeDef * ADCStructPtr);
|
||||
MyGPIO_Struct_TypeDef GPIOFromADC(MyADC_Struct_TypeDef ADC);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "stm32f10x.h"
|
||||
#include "../../Drivers/gpiodriver.h"
|
||||
#include "../../Drivers/adcdriver.h"
|
||||
|
||||
#define ADCPRE 14
|
||||
#define SQ1 0
|
||||
|
@ -9,27 +10,14 @@
|
|||
int main (void)
|
||||
{
|
||||
MyGPIO_Struct_TypeDef led = {GPIOA,5,Out_PullUp}; //led
|
||||
MyADC_Struct_TypeDef adcStruct = {ADC1,10,cycles41d5,0};
|
||||
MyGPIO_Struct_TypeDef adc = {GPIOC,0,In_Analog};
|
||||
char voltageOverflow = 0;
|
||||
|
||||
MyGPIO_Init(&led);
|
||||
MyADC_Init(&adcStruct);
|
||||
MyGPIO_Init(&adc);
|
||||
|
||||
RCC->CFGR |= RCC_CFGR_ADCPRE_1;// ADC Prescaler : divided by 6 -> 72MHz to 12MHz
|
||||
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; //We activate the clock first
|
||||
|
||||
|
||||
//ADC1->CR1 |= (0x0<<24); //Resolution 12bit -> 00
|
||||
//ADC1->CR1 |= (0x1<<5); //Interruption
|
||||
|
||||
//ADC1->CR2 |= (0x1<<30) //Software start conversion
|
||||
|
||||
ADC1->SMPR1 |= (0x4<<0); // ADC0 cycles : 41
|
||||
|
||||
//ADC_SMPR1 0x4<<WHATEV (3 bits par bidule)
|
||||
//RCC_CFGR ADCPRE(bit 14) 10
|
||||
ADC1->SQR3 |= (10<<SQ1);
|
||||
ADC1->CR2 |= (0x1<<ADON);
|
||||
while(1){
|
||||
ADC1->CR2 |= (0x1<<ADON);
|
||||
if(ADC1->DR >= 3102)
|
||||
|
|
|
@ -142,9 +142,9 @@
|
|||
<Bp>
|
||||
<Number>0</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>34</LineNumber>
|
||||
<LineNumber>29</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>134218954</Address>
|
||||
<Address>134218844</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
|
@ -153,7 +153,39 @@
|
|||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>.\Source\Principale.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression>\\cool_Simule\Source/Principale.c\34</Expression>
|
||||
<Expression>\\cool_Simule\Source/Principale.c\29</Expression>
|
||||
</Bp>
|
||||
<Bp>
|
||||
<Number>1</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>23</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>134218838</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>.\Source\Principale.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression>\\cool_Simule\Source/Principale.c\23</Expression>
|
||||
</Bp>
|
||||
<Bp>
|
||||
<Number>2</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>22</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>134218830</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>.\Source\Principale.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression>\\cool_Simule\Source/Principale.c\22</Expression>
|
||||
</Bp>
|
||||
</Breakpoint>
|
||||
<WatchWindow1>
|
||||
|
@ -329,7 +361,7 @@
|
|||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>ST-LINKIII-KEIL_SWO</Key>
|
||||
<Name>-U066FFF504955857567155843 -O206 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(1BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8000 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM)</Name>
|
||||
<Name>-U066FFF504955857567155843 -O206 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(1BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8000 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM) -WA0 -WE0 -WVCE4 -WS2710 -WM0 -WP2</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
|
@ -433,7 +465,7 @@
|
|||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>1</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\Source\Principale.c</PathWithFileName>
|
||||
|
@ -456,8 +488,8 @@
|
|||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\Drivers\adc.c</PathWithFileName>
|
||||
<FilenameWithoutPath>adc.c</FilenameWithoutPath>
|
||||
<PathWithFileName>..\Drivers\gpiodriver.c</PathWithFileName>
|
||||
<FilenameWithoutPath>gpiodriver.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
|
@ -465,11 +497,11 @@
|
|||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>3</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\Drivers\gpiodriver.c</PathWithFileName>
|
||||
<FilenameWithoutPath>gpiodriver.c</FilenameWithoutPath>
|
||||
<PathWithFileName>..\Drivers\timerdriver.c</PathWithFileName>
|
||||
<FilenameWithoutPath>timerdriver.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
|
@ -480,8 +512,8 @@
|
|||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\Drivers\timerdriver.c</PathWithFileName>
|
||||
<FilenameWithoutPath>timerdriver.c</FilenameWithoutPath>
|
||||
<PathWithFileName>..\Drivers\adcdriver.c</PathWithFileName>
|
||||
<FilenameWithoutPath>adcdriver.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
|
|
|
@ -10,13 +10,14 @@
|
|||
<TargetName>Simulé</TargetName>
|
||||
<ToolsetNumber>0x4</ToolsetNumber>
|
||||
<ToolsetName>ARM-ADS</ToolsetName>
|
||||
<pCCUsed>5060960::V5.06 update 7 (build 960)::.\ARMCC</pCCUsed>
|
||||
<uAC6>0</uAC6>
|
||||
<pArmCC>6190000::V6.19::ARMCLANG</pArmCC>
|
||||
<pCCUsed>6190000::V6.19::ARMCLANG</pCCUsed>
|
||||
<uAC6>1</uAC6>
|
||||
<TargetOption>
|
||||
<TargetCommonOption>
|
||||
<Device>STM32F103RB</Device>
|
||||
<Vendor>STMicroelectronics</Vendor>
|
||||
<PackID>Keil.STM32F1xx_DFP.2.3.0</PackID>
|
||||
<PackID>Keil.STM32F1xx_DFP.2.4.0</PackID>
|
||||
<PackURL>http://www.keil.com/pack/</PackURL>
|
||||
<Cpu>IRAM(0x20000000,0x00005000) IROM(0x08000000,0x00020000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE</Cpu>
|
||||
<FlashUtilSpec></FlashUtilSpec>
|
||||
|
@ -186,6 +187,7 @@
|
|||
<RvdsVP>0</RvdsVP>
|
||||
<RvdsMve>0</RvdsMve>
|
||||
<RvdsCdeCp>0</RvdsCdeCp>
|
||||
<nBranchProt>0</nBranchProt>
|
||||
<hadIRAM2>0</hadIRAM2>
|
||||
<hadIROM2>0</hadIROM2>
|
||||
<StupSel>8</StupSel>
|
||||
|
@ -313,7 +315,7 @@
|
|||
</ArmAdsMisc>
|
||||
<Cads>
|
||||
<interw>1</interw>
|
||||
<Optim>1</Optim>
|
||||
<Optim>2</Optim>
|
||||
<oTime>0</oTime>
|
||||
<SplitLS>0</SplitLS>
|
||||
<OneElfS>1</OneElfS>
|
||||
|
@ -322,7 +324,7 @@
|
|||
<PlainCh>0</PlainCh>
|
||||
<Ropi>0</Ropi>
|
||||
<Rwpi>0</Rwpi>
|
||||
<wLevel>2</wLevel>
|
||||
<wLevel>3</wLevel>
|
||||
<uThumb>0</uThumb>
|
||||
<uSurpInc>0</uSurpInc>
|
||||
<uC99>0</uC99>
|
||||
|
@ -393,11 +395,6 @@
|
|||
<Group>
|
||||
<GroupName>MesDrivers</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>adc.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\Drivers\adc.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>gpiodriver.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
|
@ -408,6 +405,11 @@
|
|||
<FileType>1</FileType>
|
||||
<FilePath>..\Drivers\timerdriver.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>adcdriver.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\Drivers\adcdriver.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
@ -422,13 +424,14 @@
|
|||
<TargetName>Réel</TargetName>
|
||||
<ToolsetNumber>0x4</ToolsetNumber>
|
||||
<ToolsetName>ARM-ADS</ToolsetName>
|
||||
<pCCUsed>5060960::V5.06 update 7 (build 960)::.\ARMCC</pCCUsed>
|
||||
<uAC6>0</uAC6>
|
||||
<pArmCC>6190000::V6.19::ARMCLANG</pArmCC>
|
||||
<pCCUsed>6190000::V6.19::ARMCLANG</pCCUsed>
|
||||
<uAC6>1</uAC6>
|
||||
<TargetOption>
|
||||
<TargetCommonOption>
|
||||
<Device>STM32F103RB</Device>
|
||||
<Vendor>STMicroelectronics</Vendor>
|
||||
<PackID>Keil.STM32F1xx_DFP.2.3.0</PackID>
|
||||
<PackID>Keil.STM32F1xx_DFP.2.4.0</PackID>
|
||||
<PackURL>http://www.keil.com/pack/</PackURL>
|
||||
<Cpu>IRAM(0x20000000,0x00005000) IROM(0x08000000,0x00020000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE</Cpu>
|
||||
<FlashUtilSpec></FlashUtilSpec>
|
||||
|
@ -598,6 +601,7 @@
|
|||
<RvdsVP>0</RvdsVP>
|
||||
<RvdsMve>0</RvdsMve>
|
||||
<RvdsCdeCp>0</RvdsCdeCp>
|
||||
<nBranchProt>0</nBranchProt>
|
||||
<hadIRAM2>0</hadIRAM2>
|
||||
<hadIROM2>0</hadIROM2>
|
||||
<StupSel>8</StupSel>
|
||||
|
@ -725,7 +729,7 @@
|
|||
</ArmAdsMisc>
|
||||
<Cads>
|
||||
<interw>1</interw>
|
||||
<Optim>1</Optim>
|
||||
<Optim>2</Optim>
|
||||
<oTime>0</oTime>
|
||||
<SplitLS>0</SplitLS>
|
||||
<OneElfS>1</OneElfS>
|
||||
|
@ -734,7 +738,7 @@
|
|||
<PlainCh>0</PlainCh>
|
||||
<Ropi>0</Ropi>
|
||||
<Rwpi>0</Rwpi>
|
||||
<wLevel>2</wLevel>
|
||||
<wLevel>3</wLevel>
|
||||
<uThumb>0</uThumb>
|
||||
<uSurpInc>0</uSurpInc>
|
||||
<uC99>0</uC99>
|
||||
|
@ -805,11 +809,6 @@
|
|||
<Group>
|
||||
<GroupName>MesDrivers</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>adc.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\Drivers\adc.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>gpiodriver.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
|
@ -820,6 +819,11 @@
|
|||
<FileType>1</FileType>
|
||||
<FilePath>..\Drivers\timerdriver.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>adcdriver.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\Drivers\adcdriver.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
@ -835,15 +839,15 @@
|
|||
<RTE>
|
||||
<apis/>
|
||||
<components>
|
||||
<component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="5.4.0" condition="ARMv6_7_8-M Device">
|
||||
<package name="CMSIS" schemaVersion="1.3" url="http://www.keil.com/pack/" vendor="ARM" version="5.7.0"/>
|
||||
<component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="5.6.0" condition="ARMv6_7_8-M Device">
|
||||
<package name="CMSIS" schemaVersion="1.7.7" url="http://www.keil.com/pack/" vendor="ARM" version="5.9.0"/>
|
||||
<targetInfos>
|
||||
<targetInfo name="Réel"/>
|
||||
<targetInfo name="Simulé"/>
|
||||
</targetInfos>
|
||||
</component>
|
||||
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS">
|
||||
<package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.3.0"/>
|
||||
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/>
|
||||
<targetInfos>
|
||||
<targetInfo name="Réel"/>
|
||||
<targetInfo name="Simulé"/>
|
||||
|
@ -854,7 +858,7 @@
|
|||
<file attr="config" category="header" name="RTE_Driver\Config\RTE_Device.h" version="1.1.2">
|
||||
<instance index="0">RTE\Device\STM32F103RB\RTE_Device.h</instance>
|
||||
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS"/>
|
||||
<package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.3.0"/>
|
||||
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/>
|
||||
<targetInfos>
|
||||
<targetInfo name="Réel"/>
|
||||
<targetInfo name="Simulé"/>
|
||||
|
@ -863,7 +867,7 @@
|
|||
<file attr="config" category="source" condition="STM32F1xx MD ARMCC" name="Device\Source\ARM\startup_stm32f10x_md.s" version="1.0.1">
|
||||
<instance index="0">RTE\Device\STM32F103RB\startup_stm32f10x_md.s</instance>
|
||||
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS"/>
|
||||
<package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.3.0"/>
|
||||
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/>
|
||||
<targetInfos>
|
||||
<targetInfo name="Réel"/>
|
||||
<targetInfo name="Simulé"/>
|
||||
|
@ -872,7 +876,7 @@
|
|||
<file attr="config" category="source" name="Device\Source\system_stm32f10x.c" version="1.0.1">
|
||||
<instance index="0">RTE\Device\STM32F103RB\system_stm32f10x.c</instance>
|
||||
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS"/>
|
||||
<package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.3.0"/>
|
||||
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/>
|
||||
<targetInfos>
|
||||
<targetInfo name="Réel"/>
|
||||
<targetInfo name="Simulé"/>
|
||||
|
|
Loading…
Reference in a new issue