Send time sync packets every 1000 ms
This commit is contained in:
@ -29,6 +29,8 @@
|
||||
#include "SPI_Slave_Communication.h"
|
||||
#include "Slave_Monitoring.h"
|
||||
|
||||
#include "stm32g4xx_hal_tim.h"
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@ -52,6 +54,8 @@ FDCAN_HandleTypeDef hfdcan1;
|
||||
|
||||
SPI_HandleTypeDef hspi1;
|
||||
|
||||
TIM_HandleTypeDef htim1;
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
@ -62,12 +66,18 @@ static void MX_GPIO_Init(void);
|
||||
static void MX_FDCAN1_Init(void);
|
||||
static void MX_SPI1_Init(void);
|
||||
static void MX_CRC_Init(void);
|
||||
static void MX_TIM1_Init(void);
|
||||
/* USER CODE BEGIN PFP */
|
||||
void setAMSError(void);
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim) {
|
||||
if (htim == &htim1) {
|
||||
CAN_Transmit(&hfdcan1, TIME_SYNC_ADDRESS, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
AIRStateHandler airstates;
|
||||
ErrorFlags errorflags;
|
||||
@ -105,6 +115,7 @@ int main(void) {
|
||||
MX_FDCAN1_Init();
|
||||
MX_SPI1_Init();
|
||||
MX_CRC_Init();
|
||||
MX_TIM1_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
airstates = init_AIR_State_Maschine();
|
||||
@ -112,6 +123,7 @@ int main(void) {
|
||||
set_SPI_errorInfo(&defaulterrorhandle);
|
||||
spi_communication_init(&hspi1, &airstates);
|
||||
CAN_Init(&hfdcan1);
|
||||
HAL_TIM_Base_Start_IT(&htim1);
|
||||
|
||||
HAL_GPIO_WritePin(Status_LED_GPIO_Port, Status_LED_Pin, GPIO_PIN_SET);
|
||||
// setAMSError();
|
||||
@ -285,6 +297,48 @@ static void MX_SPI1_Init(void) {
|
||||
/* USER CODE END SPI1_Init 2 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TIM1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_TIM1_Init(void) {
|
||||
|
||||
/* USER CODE BEGIN TIM1_Init 0 */
|
||||
|
||||
/* USER CODE END TIM1_Init 0 */
|
||||
|
||||
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||
|
||||
/* USER CODE BEGIN TIM1_Init 1 */
|
||||
|
||||
/* USER CODE END TIM1_Init 1 */
|
||||
htim1.Instance = TIM1;
|
||||
htim1.Init.Prescaler = 1599;
|
||||
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim1.Init.Period = 9999;
|
||||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim1.Init.RepetitionCounter = 0;
|
||||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_Base_Init(&htim1) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM1_Init 2 */
|
||||
|
||||
/* USER CODE END TIM1_Init 2 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief GPIO Initialization Function
|
||||
* @param None
|
||||
|
||||
Reference in New Issue
Block a user