ADD: DEADBEEF packet #8

This commit is contained in:
vanyabeat 2024-01-24 00:03:40 +03:00
parent 8157b41ea9
commit 578962d9fe
3 changed files with 20 additions and 7 deletions

View file

@ -41,6 +41,7 @@ void MX_USART2_UART_Init(void);
/* USER CODE BEGIN Prototypes */ /* USER CODE BEGIN Prototypes */
void USART1_PutString(char *str); void USART1_PutString(char *str);
void SendFloatsWithLL(uint8_t *buffer);
/* USER CODE END Prototypes */ /* USER CODE END Prototypes */
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -109,10 +109,9 @@ int main(void)
/* Infinite loop */ /* Infinite loop */
/* USER CODE BEGIN WHILE */ /* USER CODE BEGIN WHILE */
char buf[100];
float angle_values[200]; float angle_values[200];
uint8_t angle_index = 0; uint8_t angle_index = 0;
float ADC123_ANGLE[4] = {0, 0, 0, 0};
while (1) while (1)
{ {
if (flag_10kHz == SET) if (flag_10kHz == SET)
@ -132,11 +131,13 @@ int main(void)
average += angle_values[i]; average += angle_values[i];
} }
average /= 20.0; average /= 20.0;
float adcValue1 = GetCurrentFromADC(ReadADCValue(&hadc2, ADC_CHANNEL_15)); // Read ADC ADC123_ANGLE[0] = GetCurrentFromADC(ReadADCValue(&hadc2, ADC_CHANNEL_15)); // Read ADC
float adcValue2 = GetCurrentFromADC(ReadADCValue(&hadc2, ADC_CHANNEL_8)); // Read ADC ADC123_ANGLE[1] = GetCurrentFromADC(ReadADCValue(&hadc2, ADC_CHANNEL_8)); // Read ADC
float adcValue3 = GetCurrentFromADC(ReadADCValue(&hadc2, ADC_CHANNEL_9)); // Read ADC ADC123_ANGLE[2] = GetCurrentFromADC(ReadADCValue(&hadc2, ADC_CHANNEL_9)); // Read ADC
sprintf(buf, "ADC1:%f, ADC2:%f, ADC3:%f, ANGLE:%f\n", adcValue1, adcValue2, adcValue3, average); ADC123_ANGLE[3] = average;
USART1_PutString(buf); USART1_PutString("\xDE\xAD");
SendFloatsWithLL((uint8_t *)ADC123_ANGLE);
USART1_PutString("\xBE\xAF");
} }
if (status == 0) if (status == 0)
{ {

View file

@ -34,6 +34,17 @@ void USART1_PutString(char *str)
USART1_PutChar(*str++); USART1_PutChar(*str++);
} }
} }
void SendFloatsWithLL(uint8_t *buffer)
{
// Send each byte using LL drivers
for (size_t i = 0; i < (sizeof(float) * 4); i++)
{
while (!LL_USART_IsActiveFlag_TXE(USART1)); // Wait for TXE flag to be set
LL_USART_TransmitData8(USART1, buffer[i]); // Transmit byte
}
while (!LL_USART_IsActiveFlag_TC(USART1)); // Wait for TC flag to be set
}
/* USER CODE END 0 */ /* USER CODE END 0 */
/* USART1 init function */ /* USART1 init function */