diff --git a/Services/Batterie.c b/Services/Batterie.c new file mode 100644 index 0000000..4b8e3d2 --- /dev/null +++ b/Services/Batterie.c @@ -0,0 +1,22 @@ +#include +#include +#include +#include +#include + +int a; + +void MyBatterie_Init(void){ + MyGPIO_Init(GPIOC,4,In_Floating); // Init PORT pour recevoir tension + MyADC_Init(ADC1,14); // Init ADC pour convertir valeur + My_USART_Init(USART2); // Init USART pour envoyer batterie + MyGPIO_Init(GPIOA,2,AltOut_Ppull); // Init PORT pour envoyer pourcentage batterie + MyADC_ActiveIT(ADC1,15,&handler_ADC); // Init interruption quand conversion finie +} + +void handler_ADC (void){ + a = ADC1->DR &~ (0xF << 12); // Retourne valeur numérique + send_USART(USART2,a*13*100/12); // Envoie la valeur numérique*13 + send_USART(USART2,'%'); + start_conversion(ADC1); // Recommence la conversion pour le prochain +} \ No newline at end of file diff --git a/Services/Batterie.h b/Services/Batterie.h new file mode 100644 index 0000000..059636f --- /dev/null +++ b/Services/Batterie.h @@ -0,0 +1,7 @@ +#ifndef MYBATTERIE_H +#define MYBATTERIE_H + +void MyBatterie_Init(void); +void handler_ADC(void); + +#endif \ No newline at end of file diff --git a/Services/roulis.c b/Services/roulis.c index 0825df3..8b772e1 100644 --- a/Services/roulis.c +++ b/Services/roulis.c @@ -53,11 +53,11 @@ void MyRoulis_Data(void){ MySPI_Set_NSS(); // Fin transmission Z } -float MyRoulis_Angle(){ +int MyRoulis_Angle(){ //Calcul de l'angle alpha //int x = x1 + (x2 << 8); int y = y1 + (y2 << 8); int z = z1 + (z2 << 8); - float alpha = atan(y / z); //sqrtf(x*x + y*y) + int alpha = atan(y / z); //sqrtf(x*x + y*y) return alpha; } \ No newline at end of file diff --git a/Services/roulis.h b/Services/roulis.h index e2cd6f9..0d7bece 100644 --- a/Services/roulis.h +++ b/Services/roulis.h @@ -9,6 +9,6 @@ Ou sinon sur interruption d'un timer a 100HZ void MyRoulis_Init(void); void MyRoulis_Data(void); -float MyRoulis_Angle(); +int MyRoulis_Angle(); #endif \ No newline at end of file diff --git a/readme.txt b/readme.txt index 0e2be3f..b68695d 100644 --- a/readme.txt +++ b/readme.txt @@ -1,4 +1,4 @@ -Il faut vérifier le driver SPI sur carte et finir roulis +Driver SPI normalement bon, roulis a tester Port map carte nucléo : @@ -6,13 +6,13 @@ Plateau : Timer 3 (channel 3) ? PA1 : Output push pull (bit sens) -! PA9 : Alternate output push pull (ligne TX UART1, not used) -! PA10 : Floating input (ligne RX UART1) +! PA9 : Alternate output push pull (UART1 TX, not used) +! PA10 : Floating input (lUART1 RX) ! PB0 : Alternate output push pull (PWM) prio interruption usart1 : 6 -SPI / roulis : +Roulis : ! PA4 : Output push pull (SPI1 NSS) ! PA5 : Alternate output push pull (SPI1 SCK) @@ -20,4 +20,7 @@ SPI / roulis : ! PA7 : Alternate output push pull (SPI1 MOSI) prio interruption timer2 : 0 -Pour le roulis, je ne suis pas sur de comment retourner l'angle , il faut vérifier que le calcul soit bon aussi \ No newline at end of file +Batterie : + +?PC4 : Floating input (ADC12 CHANNEL14) +!PA2 : Alternate output push pull (UART2 TX) \ No newline at end of file