SUPP
This commit is contained in:
parent
f22d8aacd9
commit
27654ac30a
5 changed files with 230 additions and 26 deletions
22
Drivers/Include/Driver_UART.h
Normal file
22
Drivers/Include/Driver_UART.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef MYUART_H
|
||||
#define MYUART_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
typedef struct {
|
||||
USART_TypeDef * UART;
|
||||
unsigned int baudrate;
|
||||
}MyUART_Struct_Typedef;
|
||||
|
||||
void UART_send(char data);
|
||||
char UART_read(char data, MyUART_Struct_Typedef * UART);
|
||||
void UART_init(MyUART_Struct_Typedef * UART);
|
||||
void USART1_IRQHandler(void);
|
||||
void USART2_IRQHandler(void);
|
||||
void USART3_IRQHandler(void);
|
||||
void UART_InitGPIO(MyUART_Struct_Typedef * UART);
|
||||
void UART_interruption (MyUART_Struct_Typedef * UART);
|
||||
|
||||
|
||||
|
||||
#endif
|
21
Drivers/Sources/Driver_ADC.c
Normal file
21
Drivers/Sources/Driver_ADC.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef MYADC_H
|
||||
#define MYADC_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
#include "Driver_GPIO.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ADC_TypeDef * ADC;
|
||||
char Channel;
|
||||
} MyADC_Struct_TypeDef;
|
||||
|
||||
|
||||
void MyADC_Base_Init(MyADC_Struct_TypeDef * ADC);
|
||||
void MyADC_Base_Start(ADC_TypeDef * ADC);
|
||||
void MyADC_Base_Stop(ADC_TypeDef * ADC);
|
||||
void MyADC_Base_Interuption(ADC_TypeDef * ADC);
|
||||
int MyADC_Base_Result (MyADC_Struct_TypeDef * ADC);
|
||||
void MyADC_Init_Periph (void (*fct)(void));
|
||||
|
||||
#endif
|
144
Drivers/Sources/Driver_UART.c
Normal file
144
Drivers/Sources/Driver_UART.c
Normal file
|
@ -0,0 +1,144 @@
|
|||
#include "Driver_UART.h"
|
||||
#include "Driver_GPIO.h"
|
||||
|
||||
|
||||
char received_data1, received_data2, received_data3;
|
||||
|
||||
void UART_init(MyUART_Struct_Typedef * UART)
|
||||
{
|
||||
if(UART->UART ==USART1)
|
||||
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
|
||||
else if(UART->UART ==USART2)
|
||||
RCC->APB1ENR |= RCC_APB1ENR_USART2EN;
|
||||
else if(UART->UART ==USART3)
|
||||
RCC->APB1ENR |= RCC_APB1ENR_USART3EN;
|
||||
|
||||
|
||||
RCC->APB2ENR |= RCC_APB2ENR_USART1EN; // Validation horloge USART1
|
||||
USART1->CR1 |= USART_CR1_UE; // Activer l'USART
|
||||
USART1->CR1 &= ~USART_CR1_M; // Choisir la taille 8bits de donnée
|
||||
USART1->CR2 |= USART_CR2_STOP; // 1 seul bit de stop
|
||||
//USART1->BRR |= 468 << 4; // Fixe le baud rate à 9600bps partie entière
|
||||
//USART1->BRR |= 75; // Fixe le baud rate à 9600bps partie fractionnaire
|
||||
UART->UART->BRR = 72000000/(UART->baudrate);
|
||||
USART1->CR1 |= USART_CR1_TE; // Autoriser la transmission
|
||||
USART1->CR1 |= USART_CR1_RE; // Activer la réception
|
||||
// USART1->CR1 |= USART_CR1_TCIE; // Activer l'interruption de transmission
|
||||
USART1->CR1 |= USART_CR1_RXNEIE; // Activer l'interruption de réception
|
||||
UART_interruption(UART);
|
||||
|
||||
}
|
||||
|
||||
void UART_send(char data)
|
||||
{
|
||||
while(!(USART1->SR & USART_SR_TXE) | !(USART2->SR & USART_SR_TXE)){} //Attendre l'autorisation de transmission
|
||||
USART1->DR |= data;
|
||||
while(!(USART1->SR & USART_SR_TC) | !(USART2->SR & USART_SR_TC)){} //Attendre la fin de transmission
|
||||
}
|
||||
|
||||
char UART_read(char data, MyUART_Struct_Typedef * UART)
|
||||
{
|
||||
if(UART->UART == USART1)
|
||||
return received_data1;
|
||||
else if (UART->UART == USART2)
|
||||
return received_data2;
|
||||
else if (UART->UART == USART3)
|
||||
return received_data3;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void USART1_IRQHandler(void)
|
||||
{
|
||||
if (USART1->SR & USART_SR_RXNE) // si une donnée a été reçue
|
||||
{
|
||||
received_data1 = USART1->DR; // lire la donnée reçue
|
||||
}
|
||||
|
||||
if (USART1->SR & USART_SR_TC) // si la transmission est terminée
|
||||
{
|
||||
USART1->SR &= ~USART_SR_TC; // effacer le bit de transmission terminée
|
||||
}
|
||||
}
|
||||
|
||||
void USART2_IRQHandler(void)
|
||||
{
|
||||
if (USART2->SR & USART_SR_RXNE) // si une donnée a été reçue
|
||||
{
|
||||
received_data2 = USART2->DR; // lire la donnée reçue
|
||||
}
|
||||
|
||||
if (USART2->SR & USART_SR_TC) // si la transmission est terminée
|
||||
{
|
||||
USART2->SR &= ~USART_SR_TC; // effacer le bit de transmission terminée
|
||||
}
|
||||
}
|
||||
|
||||
void USART3_IRQHandler(void)
|
||||
{
|
||||
if (USART3->SR & USART_SR_RXNE) // si une donnée a été reçue
|
||||
{
|
||||
received_data3 = USART3->DR; // lire la donnée reçue
|
||||
}
|
||||
|
||||
if (USART3->SR & USART_SR_TC) // si la transmission est terminée
|
||||
{
|
||||
USART3->SR &= ~USART_SR_TC; // effacer le bit de transmission terminée
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UART_interruption (MyUART_Struct_Typedef * UART)
|
||||
{
|
||||
UART->UART->CR1 |= USART_CR1_RXNEIE;
|
||||
|
||||
if (UART->UART==USART1)
|
||||
{
|
||||
NVIC->ISER[1] |= (1<<(USART1_IRQn-32));
|
||||
}
|
||||
if (UART->UART==USART2)
|
||||
{
|
||||
NVIC->ISER[1] |= (1<<(USART2_IRQn-32));
|
||||
}
|
||||
if (UART->UART==USART3)
|
||||
{
|
||||
NVIC->ISER[1] |= (1<<(USART3_IRQn-32));
|
||||
}
|
||||
}
|
||||
|
||||
void UART_InitGPIO(MyUART_Struct_Typedef * UART)
|
||||
{
|
||||
if(UART->UART == USART1)
|
||||
{
|
||||
MyUART_Struct_Typedef UART1 = {USART1,9600};
|
||||
MyGPIO_Struct_TypeDef PA9 = {GPIOA,9,AltOut_Ppull};
|
||||
MyGPIO_Struct_TypeDef PA10 = {GPIOA,10,In_PullUp};
|
||||
MyGPIO_Init (&PA9);
|
||||
MyGPIO_Init (&PA10);
|
||||
UART_init(&UART1);
|
||||
}
|
||||
else if(UART->UART == USART2) {
|
||||
MyUART_Struct_Typedef UART2 = {USART2,9600};
|
||||
MyGPIO_Struct_TypeDef PA2 = {GPIOA,2,AltOut_Ppull};
|
||||
MyGPIO_Struct_TypeDef PA3 = {GPIOA,3,In_Floating};
|
||||
MyGPIO_Init (&PA2);
|
||||
MyGPIO_Init (&PA3);
|
||||
UART_init(&UART2);
|
||||
}
|
||||
else if(UART->UART == USART3) {
|
||||
MyUART_Struct_Typedef UART3 = {USART3,9600};
|
||||
MyGPIO_Struct_TypeDef PA10 = {GPIOA,10,AltOut_Ppull};
|
||||
MyGPIO_Struct_TypeDef PA11 = {GPIOA,11,In_PullUp};
|
||||
MyGPIO_Init (&PA10);
|
||||
MyGPIO_Init (&PA11);
|
||||
UART_init(&UART3);
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -125,7 +125,7 @@
|
|||
<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=297,604,718,1031,0)(121=-1,-1,-1,-1,0)(122=546,289,967,716,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=911,135,1505,886,0)(131=997,343,1591,1094,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=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0)</Name>
|
||||
<Name>(1010=937,133,1313,690,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=1357,482,1778,909,0)(121=-1,-1,-1,-1,0)(122=546,289,967,716,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=911,135,1505,886,0)(131=997,343,1591,1094,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=1375,56,1823,470,0)(161=1383,268,1831,682,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=240,283,843,1034,0)(151=-1,-1,-1,-1,0)</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
|
@ -143,7 +143,24 @@
|
|||
<Name>-U -O206 -S8 -C0 -P00 -N00("") -D00(00000000) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM)</Name>
|
||||
</SetRegEntry>
|
||||
</TargetDriverDllRegistry>
|
||||
<Breakpoint/>
|
||||
<Breakpoint>
|
||||
<Bp>
|
||||
<Number>0</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>69</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>134219582</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>U:\INSA\Microcontrôleur\Projet_Voilier_grp\Voilier\GPIO_Test\Sources\Main.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression>\\GPIO_Test\Sources/Main.c\69</Expression>
|
||||
</Bp>
|
||||
</Breakpoint>
|
||||
<Tracepoint>
|
||||
<THDelay>0</THDelay>
|
||||
</Tracepoint>
|
||||
|
@ -152,7 +169,7 @@
|
|||
<periodic>1</periodic>
|
||||
<aLwin>0</aLwin>
|
||||
<aCover>0</aCover>
|
||||
<aSer1>0</aSer1>
|
||||
<aSer1>1</aSer1>
|
||||
<aSer2>0</aSer2>
|
||||
<aPa>0</aPa>
|
||||
<viewmode>1</viewmode>
|
||||
|
@ -337,9 +354,9 @@
|
|||
<DebugFlag>
|
||||
<trace>0</trace>
|
||||
<periodic>1</periodic>
|
||||
<aLwin>1</aLwin>
|
||||
<aLwin>0</aLwin>
|
||||
<aCover>0</aCover>
|
||||
<aSer1>0</aSer1>
|
||||
<aSer1>1</aSer1>
|
||||
<aSer2>0</aSer2>
|
||||
<aPa>0</aPa>
|
||||
<viewmode>1</viewmode>
|
||||
|
@ -416,24 +433,24 @@
|
|||
<File>
|
||||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>3</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\Drivers\Include\Driver_GPIO.h</PathWithFileName>
|
||||
<FilenameWithoutPath>Driver_GPIO.h</FilenameWithoutPath>
|
||||
<PathWithFileName>..\Drivers\Sources\Driver_UART.c</PathWithFileName>
|
||||
<FilenameWithoutPath>Driver_UART.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>4</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\Drivers\Include\Driver_Timer.h</PathWithFileName>
|
||||
<FilenameWithoutPath>Driver_Timer.h</FilenameWithoutPath>
|
||||
<PathWithFileName>C:\Users\chanfreau\Downloads\voilier\Drivers\Sources\Driver_ADC.c</PathWithFileName>
|
||||
<FilenameWithoutPath>Driver_ADC.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
|
@ -441,7 +458,7 @@
|
|||
|
||||
<Group>
|
||||
<GroupName>SRC</GroupName>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
|
@ -449,7 +466,7 @@
|
|||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>5</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\Sources\Main.c</PathWithFileName>
|
||||
|
@ -469,7 +486,7 @@
|
|||
|
||||
<Group>
|
||||
<GroupName>::Device</GroupName>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>1</RteFlg>
|
||||
|
|
|
@ -394,14 +394,14 @@
|
|||
<FilePath>..\Drivers\Sources\Driver_Timer.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>Driver_GPIO.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\Drivers\Include\Driver_GPIO.h</FilePath>
|
||||
<FileName>Driver_UART.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\Drivers\Sources\Driver_UART.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>Driver_Timer.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\Drivers\Include\Driver_Timer.h</FilePath>
|
||||
<FileName>Driver_ADC.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>C:\Users\chanfreau\Downloads\voilier\Drivers\Sources\Driver_ADC.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
|
@ -811,14 +811,14 @@
|
|||
<FilePath>..\Drivers\Sources\Driver_Timer.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>Driver_GPIO.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\Drivers\Include\Driver_GPIO.h</FilePath>
|
||||
<FileName>Driver_UART.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\Drivers\Sources\Driver_UART.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>Driver_Timer.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\Drivers\Include\Driver_Timer.h</FilePath>
|
||||
<FileName>Driver_ADC.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>C:\Users\chanfreau\Downloads\voilier\Drivers\Sources\Driver_ADC.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
|
|
Loading…
Reference in a new issue