This commit is contained in:
Cyril Vasseur 2023-04-11 15:34:44 +02:00
parent c531decce4
commit f6fca418e1
8 changed files with 285 additions and 26 deletions

View file

@ -0,0 +1,9 @@
#ifndef CAP_voilier_H
#define CAP_voilier_H
void My_cap(void);
void Madirection_IT (void);
#endif

10
Drivers/Inc/UART.h Normal file
View file

@ -0,0 +1,10 @@
#ifndef MYUART_H
#define MYUART_H
#include "stm32f10x.h"
void MyUART_init(void);
void UART_send(char data);
void MyUART_ActiveIT(char Prio, void (*IT_function)(void));
char UART_receive(void);
#endif

View file

@ -10,6 +10,7 @@ void MyTimer_Base_Init ( MyTimer_Struct_TypeDef * Timer)
if(Timer->Timer==TIM1)
{
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
Timer->Timer->BDTR|=TIM_BDTR_MOE;
}
else if (Timer->Timer==TIM2)
{
@ -112,6 +113,7 @@ void MyTimer_ActiveIT (TIM_TypeDef * Timer, char Prio, void (*IT_function)(void)
NVIC->ISER[0] |= 0x01<<num_tim; // On précise quelle interruption on souhaite activé
NVIC->IP[num_tim] |= Prio << 4; // On précise la priorité qu'on souhaite lui donner
}
void init_encoder_timer(TIM_TypeDef * Timer) //voir page 391

65
Drivers/Src/UART.c Normal file
View file

@ -0,0 +1,65 @@
#include "UART.h"
#include "GPIO.h"
void (*uart_rx_ptr_func)(void);
void MyUART_init(void) // que pour du 9600 bauds
{
MyGPIO_Struct_TypeDef RX_pin;
MyGPIO_Struct_TypeDef TX_pin;
RX_pin.GPIO = GPIOA;
RX_pin.GPIO_Conf = In_Floating;
RX_pin.GPIO_Pin = 10;
TX_pin.GPIO = GPIOA;
TX_pin.GPIO_Conf = AltOut_Ppull;
TX_pin.GPIO_Pin = 9;
MyGPIO_Init (&RX_pin);
MyGPIO_Init (&TX_pin);
RCC->APB2ENR |= RCC_APB2ENR_USART1EN; // validation horloge USART1
USART1->CR1 |= USART_CR1_UE; // Activation de l'USART
USART1->CR1 &= ~USART_CR1_M; // Choix d'une taille de 8 bits de données
USART1->CR2 &= USART_CR2_STOP; // Choix d'un seul bit de stop
USART1->BRR |= 468 << 4; // Fixe le baud rate à 9600bps //valeurs trouvé p804
USART1->BRR |= 75; // Fixe le baud rate à 9600bps
USART1->CR1 |= USART_CR1_RE;
USART1->CR1 |= USART_CR1_TE;
}
void UART_send(char data)
{
while(!(USART1->SR & USART_SR_TXE)) // Tant que le buffer d'envoi n'est pas vide, on n'envoie pas plus de données
{
}
USART1->DR = data; // Ecriture de la donnée dans le registre DR
}
void MyUART_ActiveIT(char Prio, void (*IT_function)(void))
{
USART1->CR1 |= USART_CR1_RXNEIE; // On autorise l'interruption sur réception de l'UART
uart_rx_ptr_func=IT_function;
NVIC->ISER[1] |= 0x01<<(USART1_IRQn%32); // On précise quelle interruption on souhaite activé
NVIC->IP[USART1_IRQn] |= Prio << 4; // On précise la priorité qu'on souhaite lui donner
}
void USART1_IRQHandler()
{
if (USART1->SR & USART_SR_RXNE)
{
USART1->SR &= ~USART_SR_RXNE; // On abaisse le flag d'interruption
if(uart_rx_ptr_func!=0)
{
(*uart_rx_ptr_func)();
}
}
}
char UART_receive()
{
return USART1->DR; // on recupere dans DR
}

View file

@ -0,0 +1,48 @@
#include "UART.h"
#include "TIMER.h"
#include "GPIO.h"
MyTimer_Struct_TypeDef timer1;
void Madirection_IT (void);
signed char direction ;
int duty_cap ;
MyGPIO_Struct_TypeDef PA9;
MyGPIO_Struct_TypeDef PB1;
void My_cap(void)
{
PA9.GPIO=GPIOA;
PA9.GPIO_Conf=AltOut_Ppull;
PA9.GPIO_Pin=9;
MyGPIO_Init(&PA9);
PB1.GPIO=GPIOB;
PB1.GPIO_Conf=Out_Ppull;
PB1.GPIO_Pin=1;
MyGPIO_Init(&PB1);
timer1.Timer=TIM1;
timer1.ARR=20000; //pour avoir 20Khz
timer1.PSC=3600;
MyTimer_Base_Init(&timer1);
MyTimer_Base_Start(timer1.Timer);
MyPWM_init(timer1.Timer,2);
MyUART_init();
MyUART_ActiveIT(2,&Madirection_IT);
}
void Madirection_IT (void)
{
direction = UART_receive();
if( direction <0 )
{
MyGPIO_Set(GPIOB,1);
}else
{
MyGPIO_Reset(GPIOB,1);
}
duty_cap=(20000*(int8_t) direction)/100 ;
MyPWM_Duty(timer1.Timer,2, duty_cap );
}

View file

@ -4,12 +4,13 @@
#include "MyI2C.h"
#include "MySPI.h"
#include "Rouli.h"
#include "CAP_voilier.h"
#include <stdio.h>
void Mafonction_IT (void);
MyGPIO_Struct_TypeDef PA5;
MyGPIO_Struct_TypeDef PC13;
MyGPIO_Struct_TypeDef PB0;
MyTimer_Struct_TypeDef timer2,timer3;
//PA5 LED
//PC13 Bouton
@ -34,9 +35,14 @@ int main ( void )
MyTimer_ActiveIT(timer2.Timer,1, &Mafonction_IT);
MyTimer_Base_Start(timer2.Timer);
PB0.GPIO=GPIOB;
PB0.GPIO_Conf=AltOut_Ppull;
PB0.GPIO_Pin=0;
MyGPIO_Init(&PB0);
timer3.Timer=TIM3;
timer3.ARR=7200; //pour avoir 100ms
timer3.PSC=1000;
timer3.ARR=14400; //pour avoir 20ms
timer3.PSC=100;
MyTimer_Base_Init(&timer3);
//MyTimer_ActiveIT(timer3.Timer,2, &Mafonction_IT);
MyTimer_Base_Start(timer3.Timer);
@ -55,18 +61,7 @@ int main ( void )
while(1)
{
rouli_GetAccel(&mesures);
if(timer2.Timer->SR&=0x04)
{
if((mesures.gY <= (-0.7)) || (mesures.gY >= 0.7))
{
MyPWM_Duty(timer3.Timer,3,71);//0.985ms
test = test+1;
}
}
My_cap();
}
return 0;
}
@ -75,5 +70,11 @@ int main ( void )
void Mafonction_IT (void)
{
MyGPIO_Toggle(PA5.GPIO,5);
if((mesures.gY <= (-0.7)) || (mesures.gY >= 0.7))
{
MyPWM_Duty(timer3.Timer,3,720);//0.985ms
test = test+1;
}
}

View file

@ -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=733,260,1154,687,0)(121=-1,-1,-1,-1,0)(122=1345,565,1766,992,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=1302,9,1896,760,1)(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=-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=733,260,1154,687,0)(121=667,158,1088,585,0)(122=1345,565,1766,992,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=1141,158,1735,909,0)(131=1302,9,1896,760,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=715,50,1163,464,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>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
@ -139,6 +139,31 @@
</SetRegEntry>
</TargetDriverDllRegistry>
<Breakpoint/>
<WatchWindow1>
<Ww>
<count>0</count>
<WinNumber>1</WinNumber>
<ItemText>test</ItemText>
</Ww>
<Ww>
<count>1</count>
<WinNumber>1</WinNumber>
<ItemText>duty_cap</ItemText>
</Ww>
<Ww>
<count>2</count>
<WinNumber>1</WinNumber>
<ItemText>direction</ItemText>
</Ww>
</WatchWindow1>
<MemoryWindow1>
<Mm>
<WinNumber>1</WinNumber>
<SubType>0</SubType>
<ItemText>0x20000018</ItemText>
<AccSizeX>0</AccSizeX>
</Mm>
</MemoryWindow1>
<Tracepoint>
<THDelay>0</THDelay>
</Tracepoint>
@ -147,7 +172,7 @@
<periodic>1</periodic>
<aLwin>1</aLwin>
<aCover>0</aCover>
<aSer1>0</aSer1>
<aSer1>1</aSer1>
<aSer2>0</aSer2>
<aPa>0</aPa>
<viewmode>1</viewmode>
@ -159,7 +184,7 @@
<AscS3>0</AscS3>
<aSer3>0</aSer3>
<eProf>0</eProf>
<aLa>0</aLa>
<aLa>1</aLa>
<aPa1>0</aPa1>
<AscS4>0</AscS4>
<aSer4>0</aSer4>
@ -184,8 +209,8 @@
<LogicAnalyzers>
<Wi>
<IntNumber>0</IntNumber>
<FirstString>((PORTA &amp; 0x00000020) &gt;&gt; 5 &amp; 0x20) &gt;&gt; 5</FirstString>
<SecondString>FF000000000000000000000000000000E0FFEF400100000000000000000000000000000028504F5254412026203078303030303030323029203E3E2035000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000F03F170000000000000000000000000000000000000090020008</SecondString>
<FirstString>((porta &amp; 0x00000200) &gt;&gt; 9 &amp; 0x200) &gt;&gt; 9</FirstString>
<SecondString>00800000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303032303029203E3E2039000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000F03F170000000000000000000000000000000000000004010008</SecondString>
</Wi>
</LogicAnalyzers>
<SystemViewers>
@ -312,7 +337,7 @@
<SetRegEntry>
<Number>0</Number>
<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=900,708,1321,1113,0)(121=1464,713,1885,1118,1)(122=1281,393,1702,798,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=783,105,1377,799,1)(132=1326,11,1920,705,1)(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=692,211,912,671,1)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=1499,644,1920,1049,0)(121=1391,503,1812,908,1)(122=950,270,1371,675,1)(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=1215,466,1809,1160,0)(132=1326,108,1920,802,1)(133=-1,-1,-1,-1,0)(160=972,135,1420,549,1)(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>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
@ -335,7 +360,40 @@
<Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128 -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM))</Name>
</SetRegEntry>
</TargetDriverDllRegistry>
<Breakpoint/>
<Breakpoint>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>33</LineNumber>
<EnabledFlag>0</EnabledFlag>
<Address>134218882</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>.\Sources\CAP_voilier.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\TP1\Sources/CAP_voilier.c\33</Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>50</LineNumber>
<EnabledFlag>0</EnabledFlag>
<Address>134221314</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>..\Drivers\Src\UART.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\TP1\../Drivers/Src/UART.c\50</Expression>
</Bp>
</Breakpoint>
<WatchWindow1>
<Ww>
<count>0</count>
@ -364,7 +422,7 @@
<periodic>1</periodic>
<aLwin>1</aLwin>
<aCover>0</aCover>
<aSer1>0</aSer1>
<aSer1>1</aSer1>
<aSer2>0</aSer2>
<aPa>0</aPa>
<viewmode>1</viewmode>
@ -486,6 +544,42 @@
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>1</GroupNumber>
<FileNumber>7</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\Drivers\Inc\UART.h</PathWithFileName>
<FilenameWithoutPath>UART.h</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>1</GroupNumber>
<FileNumber>8</FileNumber>
<FileType>1</FileType>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\Drivers\Src\UART.c</PathWithFileName>
<FilenameWithoutPath>UART.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>1</GroupNumber>
<FileNumber>9</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>.\Sources\CAP_voilier.c</PathWithFileName>
<FilenameWithoutPath>CAP_voilier.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
<Group>

View file

@ -413,6 +413,21 @@
<FileType>1</FileType>
<FilePath>.\Sources\Rouli.c</FilePath>
</File>
<File>
<FileName>UART.h</FileName>
<FileType>5</FileType>
<FilePath>..\Drivers\Inc\UART.h</FilePath>
</File>
<File>
<FileName>UART.c</FileName>
<FileType>1</FileType>
<FilePath>..\Drivers\Src\UART.c</FilePath>
</File>
<File>
<FileName>CAP_voilier.c</FileName>
<FileType>1</FileType>
<FilePath>.\Sources\CAP_voilier.c</FilePath>
</File>
</Files>
</Group>
<Group>
@ -830,6 +845,21 @@
<FileType>1</FileType>
<FilePath>.\Sources\Rouli.c</FilePath>
</File>
<File>
<FileName>UART.h</FileName>
<FileType>5</FileType>
<FilePath>..\Drivers\Inc\UART.h</FilePath>
</File>
<File>
<FileName>UART.c</FileName>
<FileType>1</FileType>
<FilePath>..\Drivers\Src\UART.c</FilePath>
</File>
<File>
<FileName>CAP_voilier.c</FileName>
<FileType>1</FileType>
<FilePath>.\Sources\CAP_voilier.c</FilePath>
</File>
</Files>
</Group>
<Group>