2016-02-13 01:26 PM
Hi guys
I recently started to learn STM32F407. I'm sticking to a problem which likes drinking a glass of water for you, so please help me, I studied many tutorials and watched many videos butnone explains these modules when they are used together.
I want to continuously sample two channel simultaneously at 10 ksps-12 bit, then send its data through UART to MATLAB.I used Cubemx to create configuration and initialization for this project but it doesn't use HAL library for multi channels ADC. According to HAL driver user Manual:Multi mode ADCs Regular channels configuration
My 1st problem is how to handle this part.
My 2nd problem is general question. Is it correct to use ''HAL_TIM_PeriodElapsedCallback()'' to trigger ADC to start sampling plus send its data through UART?If you help me by utilizing Cubemx, I am really appreciate. Otherwise I still thanks you for any help likes example code(which include all these parts together) and whatever you can provide. #adc #multi-mode-adc #dual-mode-adc-stm32f4 #stm32f4 #dma #usart #no-hablo-hal2016-02-14 02:56 AM
2016-02-14 10:12 AM
Seems no one wants to contribute!
Pondering the forum participation irony there.2016-02-14 10:38 AM
Here's how I would do it:
Set up the ADCs to trigger off of a timer and record into a circular buffer in DMA mode. Not sure off-hand how to made ADC1 and ADC2 sample simultaneously, but I'm sure there's a way.On the DMA half-complete transfer, send the first half of the buffer out through UART.On the DMA complete transfer, send out the second half of the buffer.2016-02-14 11:58 AM
When I finish this project, I will create a full tutorial for it. I know many people will find it useful especially with this new HAL_driver!
I found many post of you (you have two users?) helping people with their projects. I hope you like to continue your collaboration. I know one day these helps will come back to you.2016-02-14 12:39 PM
Sure, of course I am using DMA. But I don't know how implement it correctly.
I am going to use ''HAL_ADCEx_MultiModeGetValue(&hadc1);''according to its definition, it return ADC_CDR which contains both ADC1 & ADC2 values. I am going to do this. Do you think I am correct?char senddata1[];char senddata2[];__IO uint32_t ADC_val=0;__IO uint16_t ADC1_val=0;__IO uint16_t ADC2_val=0;ADC_val=HAL_ADCEx_MultiModeGetValue(&hadc1); // it is 32 bit value, I am not sureADC1_val=(ADC_val)&0xFFFF; //extract lower 16 bitADC2_val=(ADC_val>>16)&0xFFFF; //extract higher 16 bitsprintf(senddata1,''%d'', ADC_val1); sprintf(senddata2,''%d'', ADC_val2); HAL_UART_Transmit(&huart3, (uint8_t*)&senddata1,1,10000); //transmit every time interrupt happen.Is Size=1 correct?
HAL_UART_Transmit(&huart3, (uint8_t*)&senddata2,1,10000);My second question: for single conversion I am using ''HAL_ADC_ConvCpltCallback'' in order to initiate uart transmission, but I can't find any call back for multi mode! how about using ''ADC_MultiModeDMAConvCplt'' ?This the function definition:uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef* hadc)
{ /* Return the multi mode conversion value */ return ADC->CDR; }2016-02-14 06:43 PM
> I am going to use ''HAL_ADCEx_MultiModeGetValue(&hadc1);''
according to its definition, it return ADC_CDR which contains both ADC1 & ADC2 values. I am going to do this. Do you think I am correct?Not sure, I'd put known voltages on the lines and see if they match your expectation.> My second question: for single conversion I am using ''HAL_ADC_ConvCpltCallback'' in order to initiate uart transmission, but I can't find any call back for multi mode! how about using ''ADC_MultiModeDMAConvCplt'' ?I'd imagine since you're using ADC1 as the master ADC, the callback is the same as for single mode. That is, HAL_ADC_ConvCpltCallback will trigger when the conversion is done, if you've set things up correctly.> HAL_UART_Transmit(&huart3, (uint8_t*)&senddata1,1,10000); //transmit every time interrupt happen.Is Size=1 correct?
It looks like you're sending a string of variable length, so you should be using strlen(senddata1) + 1 instead. Note that since your baud rate is 92.1x your sample rate, you only have enough time to send 92 bits across UART, which I doubt is enough for your cose. You'll likely need to send these asynchronously (via DMA), or pool a bunch of values and send them all at once.It may help to start with a simpler example, such as doing only a single ADC instead of two. Even if it's not exactly what you want, you end up learning things in the process.