UART : GPIO selection add

This commit is contained in:
Cedric Chanfreau 2023-04-04 15:17:52 +02:00
父節點 582dd2b5b7
當前提交 a9d0437841
共有 4 個文件被更改,包括 85 次插入66 次删除

查看文件

@ -14,8 +14,7 @@ void UART_init(MyUART_Struct_Typedef * UART);
void USART1_IRQHandler(void); void USART1_IRQHandler(void);
void USART2_IRQHandler(void); void USART2_IRQHandler(void);
void USART3_IRQHandler(void); void USART3_IRQHandler(void);
void UART_InitGPIO(MyUART_Struct_Typedef * UART);

查看文件

@ -1,4 +1,5 @@
#include "Driver_UART.h" #include "Driver_UART.h"
#include "Driver_GPIO.h"
char received_data1, received_data2, received_data3; char received_data1, received_data2, received_data3;
@ -102,6 +103,40 @@ void UART_interruption (MyUART_Struct_Typedef * UART)
{ {
NVIC->ISER[1] |= (1<<(USART3_IRQn-32)); 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> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>DLGDARM</Key> <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=865,485,1286,912,1)(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=1131,175,1579,589,1)(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=-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=1357,482,1778,909,1)(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=1345,64,1793,478,1)(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=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0)</Name>
</SetRegEntry> </SetRegEntry>
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
@ -147,56 +147,24 @@
<Bp> <Bp>
<Number>0</Number> <Number>0</Number>
<Type>0</Type> <Type>0</Type>
<LineNumber>30</LineNumber> <LineNumber>38</LineNumber>
<EnabledFlag>1</EnabledFlag> <EnabledFlag>0</EnabledFlag>
<Address>0</Address> <Address>134219492</Address>
<ByteObject>0</ByteObject> <ByteObject>0</ByteObject>
<HtxType>0</HtxType> <HtxType>0</HtxType>
<ManyObjects>0</ManyObjects> <ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject> <SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess> <BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount> <BreakIfRCount>1</BreakIfRCount>
<Filename>.\Sources\Main.c</Filename> <Filename>U:\INSA\Microcontrôleur\Projet_Voilier_grp\Voilier\Drivers\Sources\Driver_UART.c</Filename>
<ExecCommand></ExecCommand> <ExecCommand></ExecCommand>
<Expression></Expression> <Expression>\\GPIO_Test\../Drivers/Sources/Driver_UART.c\38</Expression>
</Bp> </Bp>
<Bp> <Bp>
<Number>1</Number> <Number>1</Number>
<Type>0</Type> <Type>0</Type>
<LineNumber>30</LineNumber> <LineNumber>39</LineNumber>
<EnabledFlag>1</EnabledFlag> <EnabledFlag>0</EnabledFlag>
<Address>134219668</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\30</Expression>
</Bp>
<Bp>
<Number>2</Number>
<Type>0</Type>
<LineNumber>70</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134219784</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\70</Expression>
</Bp>
<Bp>
<Number>3</Number>
<Type>0</Type>
<LineNumber>71</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address> <Address>0</Address>
<ByteObject>0</ByteObject> <ByteObject>0</ByteObject>
<HtxType>0</HtxType> <HtxType>0</HtxType>
@ -204,7 +172,39 @@
<SizeOfObject>0</SizeOfObject> <SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess> <BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount> <BreakIfRCount>0</BreakIfRCount>
<Filename>.\Sources\Main.c</Filename> <Filename>..\Drivers\Sources\Driver_UART.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
<Bp>
<Number>2</Number>
<Type>0</Type>
<LineNumber>54</LineNumber>
<EnabledFlag>0</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>..\Drivers\Sources\Driver_UART.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
<Bp>
<Number>3</Number>
<Type>0</Type>
<LineNumber>67</LineNumber>
<EnabledFlag>0</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>..\Drivers\Sources\Driver_UART.c</Filename>
<ExecCommand></ExecCommand> <ExecCommand></ExecCommand>
<Expression></Expression> <Expression></Expression>
</Bp> </Bp>

查看文件

@ -10,26 +10,10 @@ int main (void){
//Déclaration d'une LED et d'un BP par structure GPIO //Déclaration d'une LED et d'un BP par structure GPIO
MyGPIO_Struct_TypeDef LED; MyGPIO_Struct_TypeDef LED;
MyGPIO_Struct_TypeDef BP; MyGPIO_Struct_TypeDef BP;
MyUART_Struct_Typedef UART;
//Déclaration d'un Timer 500 ms //Déclaration d'un Timer 500 ms
MyTimer_Struct_TypeDef TIM500ms; MyTimer_Struct_TypeDef TIM500ms;
//Déclaration de l'UART /
MyUART_Struct_Typedef UART1 = {USART1,9600};
MyUART_Struct_Typedef UART2 = {USART2,9600};
//UART2
//MyGPIO_Struct_TypeDef PA2 = {GPIOA,2,AltOut_Ppull};
//MyGPIO_Struct_TypeDef PA3 = {GPIOA,3,In_PullUp};
//UART1
MyGPIO_Struct_TypeDef PA9 = {GPIOA,9,AltOut_Ppull};
MyGPIO_Struct_TypeDef PA10 = {GPIOA,10,In_Floating};
//MyGPIO_Init (&PA2);
//MyGPIO_Init (&PA3);
MyGPIO_Init (&PA9);
MyGPIO_Init (&PA10);
//Config LED PA5 //Config LED PA5
LED.GPIO_Conf = Out_Ppull; LED.GPIO_Conf = Out_Ppull;
@ -49,6 +33,9 @@ int main (void){
TIM500ms.ARR = 5000; TIM500ms.ARR = 5000;
MyTimer_Base_Init(&TIM500ms); MyTimer_Base_Init(&TIM500ms);
//InitUART
UART.UART = USART1;
/* /*
TIM2->DIER |= 1<< 0 ; //INTERRUPTION PERIPH TIM2->DIER |= 1<< 0 ; //INTERRUPTION PERIPH
//TIM2->DIER |= TIM_DIER_UIE ; //TIM2->DIER |= TIM_DIER_UIE ;
@ -62,17 +49,15 @@ int main (void){
UART_init(&UART1);
UART_init(&UART2);
//NVIC_EnableIRQ(USART1_IRQn);// Activer les interruptions //NVIC_EnableIRQ(USART1_IRQn);// Activer les interruptions
UART_InitGPIO(&UART);
// Envoyer les données // Envoyer les données
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
UART_send(data[i]); UART_send(data[i]);
} }
UART_read(data[i], &UART1); UART_read(data[i], &UART);