2022-02-07 09:28 AM
uint32_t dma_buffer_for_adc;
uint32_t adc_value_1;
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
adc_value_1 = dma_buffer_for_adc ;//
}
HAL_ADC_Start_DMA (&hadc1, &dma_buffer_for_adc, 1);
here I have implemented a single channel continuous conversion mode.I wrote the address of the dma buffer and the code works great. adc doesn't work if I don't specify it here as a pointer.
uint32_t dma_buffer_for_adc[2]; //We have created an array with two elements, this array has 2 elements, element 0 and element 1.
uint32_t adc_value_1;
uint32_t adc_value_2;
//-----------------------------------------------------------------------------------------------------------------------------------
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
adc_value_1 = dma_buffer_for_adc[0]; //We have defined the buffer where the / adc value is kept to a variable
adc_value_2 = dma_buffer_for_adc[1];
}
//-----------------------------------------------------------------------------------------------------------------------------------
HAL_ADC_Start_DMA (&hadc1, dma_buffer_for_adc, 2);
here I have implemented a multichannel channel continuous conversion mode.I wrote the address of the dma buffer and the code works great.
Here is the thing that confuses me. Why do we need to specify addresses when doing a single channel conversion and not if we use multiple channels?
Solved! Go to Solution.
2022-02-08 07:14 AM
dma can only work with array or pointer. pointer and array are very close concepts. You can access pointer elements like arrays and array elements like pointers.The main difference between pointer and array is that one is stored in the heap and the other in the stack. In your first example, you are telling the compiler to treat your variable as an array with the & symbol. Ignoring the [] symbols, you don't need to do anything special since you are already using arrays in your 2nd example. I guess you are thinking of pointer and array as completely different concepts.
the following two notations produce the same result
char MyArray[2];
*(MyArray) = 'a';
*(MyArray+1) = 'b';
char *MyPointer;
char a = MyPointer[0];
2022-02-07 06:14 PM
> uint32_t dma_buffer_for_adc[1]; // We have created an array with two elements, this array has 2 elements, element 0 and element 1.
This array has one element, not two.
> adc_value_2 = dma_buffer_for_adc[1];
This access is out of bounds, and will likely take the value of adc_value_1 if they're allocated consecutively.
> Here is the thing that confuses me. Why do we need to specify addresses when doing a single channel conversion and not if we use multiple channels?
Not sure what you mean. You need to specify an address (i.e. a pointer to data) in both cases if you're using HAL_ADC_Start_DMA.
> HAL_ADC_Start_DMA (&hadc1, dma_buffer_for_adc[], 2);
This isn't valid syntax and throws an error in GCC.
main.cpp: In function 'int main(int, char**)':
main.cpp:78:49: error: expected primary-expression before ']' token
HAL_ADC_Start_DMA(nullptr, dma_buffer_for_adc[], 2);
^
If you lose the "[]", then dma_buffer_for_adc is a pointer of type (uint32_t *).
2022-02-08 07:14 AM
dma can only work with array or pointer. pointer and array are very close concepts. You can access pointer elements like arrays and array elements like pointers.The main difference between pointer and array is that one is stored in the heap and the other in the stack. In your first example, you are telling the compiler to treat your variable as an array with the & symbol. Ignoring the [] symbols, you don't need to do anything special since you are already using arrays in your 2nd example. I guess you are thinking of pointer and array as completely different concepts.
the following two notations produce the same result
char MyArray[2];
*(MyArray) = 'a';
*(MyArray+1) = 'b';
char *MyPointer;
char a = MyPointer[0];