Batterie v2

This commit is contained in:
leo 2025-11-26 21:00:06 +01:00
parent 624aa536d5
commit 0c1e39ffd6

View file

@ -4,19 +4,30 @@
#include <ADC.h> #include <ADC.h>
#include <USART.h> #include <USART.h>
int d; float d;
short v;
int p;
void MyBatterie_Init(void){ void MyBatterie_Init(void){
MyGPIO_Init(GPIOC,4,In_Floating); // Init PORT pour recevoir tension MyGPIO_Init(GPIOC,4,In_Analog); // Init PORT pour recevoir tension
MyGPIO_Init(GPIOA,2,AltOut_Ppull); // Init PORT UART2 TX pour envoyer pourcentage batterie
MyGPIO_Init(GPIOA,3,In_Floating);
MyADC_Init(ADC1,14); // Init ADC channel 14 pour convertir valeur MyADC_Init(ADC1,14); // Init ADC channel 14 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 MyADC_ActiveIT(ADC1,15,&handler_ADC); // Init interruption quand conversion finie
My_USART_Init(USART2); // Init USART pour envoyer batterie
start_conversion(ADC1); // Premiere conversion
} }
void handler_ADC (void){ void handler_ADC (void){
d = ADC1->DR &~ (0xF << 12); // Retourne valeur numérique d = ADC1->DR &~ (0xF << 12); // Retourne valeur numérique
send_USART(USART2,d*13*100/12); // Envoie la valeur numérique*13 d = d*3.3/4096;
d = d*13*100/12;
p = (int) d;
send_USART(USART2,(p/10) + '0'); // Envoie le chiffre des dizaines
send_USART(USART2,(p%10) + '0'); // Envoie le chiffre des unités
send_USART(USART2,'%'); send_USART(USART2,'%');
start_conversion(ADC1); // Recommence la conversion pour le prochain start_conversion(ADC1); // Recommence la conversion pour le prochain
} }