Question
sprintf not working when ADC started
I'm trying to send ADC results over to a receiver via UART, but somewhy the program freezes on sprintf() IF I have called HAL_ADC_Start_DMA() before. If I call sprintf() before HAL_ADC_Start_DMA() it works fine. However, I need to call it after starting the DMA. How can I fix this?
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* Configure the peripherals common clocks */
PeriphCommonClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_MEMORYMAP_Init();
MX_ADC1_Init();
MX_LPUART1_UART_Init();
/* USER CODE BEGIN 2 */
uint32_t values[4] = {0, 0, 0, 0};
HAL_ADC_Start_DMA(&hadc1, values, 4);
char str[100];
sprintf(str, "TEMP_ADC: %d\n", values[1]);
int size = (int)(ceil(log10(values[1]))+12)*sizeof(char);
HAL_UART_Transmit(&hlpuart1, str, size, 100);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, SET);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_Delay(1000);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
