2019-08-17 12:10 PM
2019-08-19 07:27 AM
Okay, i have working code. I just did what says the example(before i wasn't about examples in documentatnion).
If somebody will also problem with it, heres solution.
Cube conf:
And code:
/* USER CODE BEGIN PV */
int data[5];
/* USER CODE END PV */
...
/* USER CODE BEGIN 2 */
if(HAL_ADCEx_Calibration_Start(&hadc) != HAL_OK){
Error_Handler();
}
if(HAL_ADC_Start_DMA(&hadc, data, 5) != HAL_OK){
Error_Handler();
}
/* USER CODE END 2 */
...
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_Delay(1);//for debugger stopping only
/* USER CODE END WHILE */
Thanks all for help!
2019-08-17 04:36 PM
DMA interrupt when the count decrements to zero ?
I'm reluctant to provide more help without seeing substantial effort by yourself to solve the problem.
Cheers, Hal
2019-08-18 10:41 AM
My currently conf is:
My code:
/* USER CODE BEGIN PV */
int reading[];
/* USER CODE END PV */
...
/* USER CODE BEGIN PFP */
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc){
int i;
for(i = 0; i<3; i++){
reading[i] = HAL_ADC_GetValue(&hadc);
}
}
/* USER CODE END PFP */
...
/* USER CODE BEGIN 2 */
HAL_ADC_Start_IT(&hadc);
/* USER CODE END 2 */
Debbugger says, thats not entering into a ConvCplt callback function.
And if i stop manually, of course reading 0, 1, 2 are empty.
ADC interrupt is also Set in NVIC section.
In the Description of HAL and low-layer drivers is written, that:
"
ADC conversion by interruption:
Activate the ADC peripheral and start conversions using function
HAL_ADC_Start_IT()
Wait for ADC conversion completion by call of function
HAL_ADC_ConvCpltCallback() (this function must be implemented in user
program)
Retrieve conversion results using function HAL_ADC_GetValue()
Stop conversion and disable the ADC peripheral using function
HAL_ADC_Stop_IT()
"
I made all of them, except stopping(last point), becouse im running on continous conversion.
2019-08-18 11:09 AM
Pretty sure HAL_ADC_GetValue() doesn't work like that.
WHY can't you just use DMA to fill the reading[] array?
2019-08-18 12:09 PM
1: There is no meaning of putting HAL_ADC_GetValue in a loop and if you are putting array to save data register value in continuous mode than logic is not correct.
2: First, check your ADC working properly or not, by checking EOC bit of ADC status register.
3: Second, Confirm your ADC Interrupt is working or not. Have you enabled EOCIE bit and NVIC ADC Interrupt properly? you can also write your handler for ADC interrupt.
2019-08-18 03:37 PM
OK, i cant do it, it's too difficult. Lets try the Polling mode. Now my conf looks like this:
And my code:
/* USER CODE BEGIN PV */
uint16_t reading[3];
/* USER CODE END PV */
...
/* USER CODE BEGIN WHILE */
while (1) {
HAL_ADC_Start(&hadc);
HAL_ADC_PollForConversion(&hadc, 200);
reading[0] = HAL_ADC_GetValue(&hadc);
HAL_ADC_PollForConversion(&hadc, 200);
reading[1] = HAL_ADC_GetValue(&hadc);
HAL_ADC_PollForConversion(&hadc, 200);
reading[2] = HAL_ADC_GetValue(&hadc);
HAL_ADC_Stop(&hadc);
/* USER CODE END WHILE */
Now, readings from 3 channels are completely random. I set three pots, first(CH2) have grond on output, second(CH3) have some from 1 to 3V, and the third(CH4) have Vcc potential(3.3V).
If i stop debugger at HAL_ADC_Stop(&hadc), readings looks like completely random, eg:
0: 1720
1: 1720
2: 4030
always first 2 readings are from CH3, and 3rd reading from CH4.
Wheres CH2? And why CH3 are doubled?
Theres any way to SIMPLE read more channels than one?
2019-08-18 06:21 PM
Theres any way to SIMPLE read more channels than one?
Yes. As clive pointed out, set up DMA ADC conversion to place the 3 conversions in a buffer. Poll the DMA transfer count, and when it decrements to zero, read the buffer values. Or, you can set up a DMA interrupt to trigger when the DMA count is zero.
There is a DMA ADC example in the library package. Usually the example converts one ADC channel, you will have to modify it to convert 3 channels.
Regards, Hal
2019-08-19 07:27 AM
Okay, i have working code. I just did what says the example(before i wasn't about examples in documentatnion).
If somebody will also problem with it, heres solution.
Cube conf:
And code:
/* USER CODE BEGIN PV */
int data[5];
/* USER CODE END PV */
...
/* USER CODE BEGIN 2 */
if(HAL_ADCEx_Calibration_Start(&hadc) != HAL_OK){
Error_Handler();
}
if(HAL_ADC_Start_DMA(&hadc, data, 5) != HAL_OK){
Error_Handler();
}
/* USER CODE END 2 */
...
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_Delay(1);//for debugger stopping only
/* USER CODE END WHILE */
Thanks all for help!