main commencé + emetteur_rf changé

This commit is contained in:
Cavailles Kevin 2020-11-14 16:13:49 +01:00
parent e56c871761
commit 89850bfc2f
3 changed files with 49 additions and 23 deletions

View file

@ -42,11 +42,14 @@ void emetteur_rf_init(void){
LL_USART_SetBaudRate(uart_port, periph_speed, baudrate);
*/}
void emetteur_send_bytes(USART_TypeDef * uart_port,char* buf, int len){
void emetteur_send_bytes(char* buf, int len){
for(int i = 0; i < len; i++){
LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_11);
LL_USART_TransmitData8(uart_port, buf[i]);
while(!LL_USART_IsActiveFlag_TXE(uart_port));
LL_USART_TransmitData8(USART1, buf[i]);
while(!LL_USART_IsActiveFlag_TXE(USART1));
LL_GPIO_ResetOutputPin(GPIOA,LL_GPIO_PIN_11);
}
}

View file

@ -8,7 +8,7 @@
#include "stm32f1xx_ll_gpio.h"
void emetteur_rf_init(void);
void emetteur_send_bytes(USART_TypeDef * uart_port,char* buf, int len);
void emetteur_send_bytes(char* buf, int len);

View file

@ -21,6 +21,7 @@
#include "stm32f1xx_ll_system.h" // utile dans la fonction SystemClock_Config
#include "stm32f1xx_ll_bus.h"
#include "RFInput.h"
#include "IncrEncoder.h"
#include "DcMotor.h"
@ -28,6 +29,9 @@
#include "alimentation.h"
#include "accelerometer.h"
#define CONTROL_LOOP_PERIOD 250
#define MSG_TRANSFER_PERIOD 3000
void SystemClock_Config(void);
/* Private functions ---------------------------------------------------------*/
@ -38,18 +42,18 @@ void SystemClock_Config(void);
* @retval None
*/
int val = 0;
int val2 = 0;
int counter = 0;
float level;
int level_enough;
double xx,yy;
int bon;
int battery_level_good = 0;
int angle_roulis_good = 0;
int angle_sail = 0;
int RF_Input_Duty = 0;
int TX_Flag = 0, CONTROL_LOOP_Flag = 0;
int main(void)
{
/* Configure the system clock to 72 MHz */
SystemClock_Config();
//alimentation_init();
RF_INPUT_Init();
DC_MOTOR_Init();
@ -59,20 +63,39 @@ int main(void)
/* Infinite loop */
while (1)
{
LL_mDelay(100);
//counter = (counter + 1) % 100;
//DC_MOTOR_SetSpeed(counter);
//val = RF_INPUT_GetPeriodUs();
//val2 = RF_INPUT_GetDutyTimeUs();
//SAIL_SetAngle(counter);
//level = get_battery_level();
//level_enough = is_level_enough();
xx = accelero_get_x();
//yy = accelero_get_y();
//bon = accelero_angle_bon();
if(CONTROL_LOOP_Flag){
battery_level_good = is_level_enough();
angle_roulis_good = accelero_angle_bon();
if(!angle_roulis_good){
SAIL_SetAngle(90);
DC_MOTOR_SetSpeed(0);
}else{
angle_sail = INCR_ENCODER_GetAngle();
SAIL_SetAngle(angle_sail/2);
RF_Input_Duty = RF_INPUT_GetDutyTimeRelative();
DC_MOTOR_SetSpeed(RF_Input_Duty);
}
CONTROL_LOOP_Flag = 0;
}
if(TX_Flag){
TX_Flag = 0;
}
}
}
void SysTick_Handler(void)
{
if(counter % CONTROL_LOOP_PERIOD == 0){
CONTROL_LOOP_Flag = 1;
}
if(counter % MSG_TRANSFER_PERIOD == 0){
TX_Flag = 1;
}
counter = (counter+1) % (CONTROL_LOOP_PERIOD*MSG_TRANSFER_PERIOD) ;
}