Works succesfully!

This commit is contained in:
2025-12-18 22:42:12 +03:00
parent 7ff25c2893
commit e45a7b89e9
9 changed files with 4277 additions and 4020 deletions
+23 -2
View File
@@ -67,9 +67,10 @@ volatile uint32_t curr_step_start_N = 0;
/* ADC1 circular DMA buffer definition */
uint16_t ADC1_buff_circular[ADC_BUFF_SIZE];
char ADC_msg[] = "Received ADC value: ??????????\r\n";
char ADC_msg[] = "curr_step ?????? ??????????\r\n";
#define ADC_msg_len 32
#define ADC_msg_val_pos 20
#define ADC_msg_step_pos 12
/* USER CODE END 0 */
/**
@@ -118,13 +119,16 @@ int main(void)
ADC_proc.sum = 0;
ADC_proc.avg = 0;
uint32_t curr_points_N_max = 100;
uint32_t curr_points_N =0;
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_GPIO_TogglePin(LED_RED_GPIO_Port, LED_RED_Pin);
//HAL_GPIO_TogglePin(LED_RED_GPIO_Port, LED_RED_Pin);
//HAL_Delay(100);
if (ADC_proc_shadow.status == 2) {
@@ -144,7 +148,24 @@ int main(void)
ADC_msg[ADC_msg_val_pos + 7] = (ADC_proc_shadow.avg / 100) % 10 + '0';
ADC_msg[ADC_msg_val_pos + 8] = (ADC_proc_shadow.avg / 10) % 10 + '0';
ADC_msg[ADC_msg_val_pos + 9] = (ADC_proc_shadow.avg / 1) % 10 + '0';
ADC_msg[ADC_msg_step_pos + 0] = (Sweep_state.curr_step_N / 100000) % 10 + '0';
ADC_msg[ADC_msg_step_pos + 1] = (Sweep_state.curr_step_N / 10000) % 10 + '0';
ADC_msg[ADC_msg_step_pos + 2] = (Sweep_state.curr_step_N / 1000) % 10 + '0';
ADC_msg[ADC_msg_step_pos + 3] = (Sweep_state.curr_step_N / 100) % 10 + '0';
ADC_msg[ADC_msg_step_pos + 4] = (Sweep_state.curr_step_N / 10) % 10 + '0';
ADC_msg[ADC_msg_step_pos + 5] = (Sweep_state.curr_step_N / 1) % 10 + '0';
CDC_Transmit_FS((uint8_t *)ADC_msg, ADC_msg_len);
//HAL_GPIO_TogglePin(LED_RED_GPIO_Port, LED_RED_Pin);
if (Sweep_state.curr_step_N > 1000){
Sweep_state.curr_step_N = 0;
HAL_GPIO_TogglePin(LED_RED_GPIO_Port, LED_RED_Pin);
HAL_DelayUS(10);
CDC_Transmit_FS((uint8_t *)"Sweep_start\n\r", 14);
}
}
//CDC_Transmit_FS((uint8_t *)"Hello from STM32!\r\n", 19);
+5
View File
@@ -211,6 +211,7 @@ void EXTI0_IRQHandler(void)
} else{
Sweep_state.curr_step_started_flag =2; // second half DMA buffer
}
Sweep_state.curr_step_N++;
/* USER CODE END EXTI0_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(CURR_STEP_START_TRG_Pin);
/* USER CODE BEGIN EXTI0_IRQn 1 */
@@ -267,6 +268,7 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
HAL_GPIO_WritePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin, GPIO_PIN_SET);
if (Sweep_state.curr_step_started_flag == 2) {
Sweep_state.curr_step_started_flag = 0; // reset flag after processing second half
for (uint32_t i = ADC_BUFF_SIZE/2; i < Sweep_state.curr_step_start_DMA_N; i++) {
ADC_proc.sum += ADC1_buff_circular[i];
}
@@ -297,6 +299,8 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
}
ADC_proc.N += ADC_BUFF_SIZE - ADC_BUFF_SIZE/2;
}
//if (0){
if (ADC_proc.N >= ADC_BUFF_SIZE*100){
ADC_proc_shadow.sum = ADC_proc.sum;
ADC_proc_shadow.avg = ADC_proc.avg;
@@ -319,6 +323,7 @@ void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc)
HAL_GPIO_TogglePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin);
if (Sweep_state.curr_step_started_flag == 1) {
Sweep_state.curr_step_started_flag = 0;
for (uint32_t i = 0; i < Sweep_state.curr_step_start_DMA_N; i++) {
ADC_proc.sum += ADC1_buff_circular[i];
}
+1397 -1196
View File
File diff suppressed because it is too large Load Diff
BIN
View File
Binary file not shown.
Binary file not shown.
+1218 -1206
View File
File diff suppressed because it is too large Load Diff
+715 -712
View File
File diff suppressed because it is too large Load Diff
+901 -886
View File
File diff suppressed because it is too large Load Diff
Binary file not shown.