on
2020-12-02
02:21 AM
- edited on
2024-06-03
01:28 AM
by
Laurids_PETERSE
This series of articles will provide you with:
Part 1 of the article is available here
File → New STM32 project → STM32L476RG (NUCLEO)
Pinout & Configuration tab → System Core → SYS
Select Debug interface: Serial Wire
1. USER CODE Includes section
#include <stdio.h>
2. USER CODE PD
#define ADC_BUF_SIZE 20
3. USER CODE PV
static uint32_t adcBuf[ADC_BUF_SIZE];
static uint32_t adcFlag = RESET;
4. USER CODE 0
int _write(int file, char *ptr, int len)
{
HAL_UART_Transmit(&huart2,(uint8_t*)ptr,len,100);
return len;
}
5. USER CODE 2
HAL_ADCEx_Calibration_Start(&hadc1,ADC_SINGLE_ENDED);
HAL_ADCEx_Calibration_Start(&hadc2,ADC_SINGLE_ENDED);
LL_ADC_SetMultiDMATransfer(ADC123_COMMON,LL_ADC_MULTI_REG_DMA_LIMIT_RES12_10B); //One shot MDMA mode
HAL_ADCEx_MultiModeStart_DMA(&hadc1,adcBuf,ADC_BUF_SIZE);
__HAL_DMA_DISABLE_IT(&hdma_adc1,DMA_IT_HT); //Avoid DMA half transfer interrupt trigger
6. USER CODE 3
if (adcFlag)
{
printf("-------------\r\n");
for(uint32_t i=0;i<ADC_BUF_SIZE;i++)
{
printf("%u\r\n",(uint16_t)(adcBuf[i]&0x0000FFFF)); //LSB -> MASTER
printf("%u\r\n",(uint16_t)(adcBuf[i]>>16)); //MSB -> SLAVE
}
HAL_Delay(1000);
adcFlag = RESET;
HAL_ADCEx_MultiModeStart_DMA(&hadc1,adcBuf,ADC_BUF_SIZE);
__HAL_DMA_DISABLE_IT(&hdma_adc1,DMA_IT_HT);
}
7. USER CODE 4
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *AdcHandle)
{
adcFlag = SET;
}
@Laurids_PETERSEN
I tried the steps, but there is an error on :
LL_ADC_SetMultiDMATransfer(ADC123_COMMON,LL_ADC_MULTI_REG_DMA_LIMIT_RES12_10B); //One shot MDMA mode
Description Resource Path Location Type
'ADC123_COMMON' undeclared (first use in this function); did you mean 'ADC12_COMMON'? main.c / ADC_interleaved/ Core/ Src line 113 C/C++ Problem
it should be ADC12_COMMON
Update: I was generating code On STMG4, I tried this on STM32L476RG as explained above, and the code is correct: ADC123_COMMON