2020-03-31 04:45 PM
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "fatfs.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "fatfs_sd.h"
#include "string.h"
#include "stm32l4xx_hal_adc.h"
/* Private variables ---------------------------------------------------------*/
ADC_HandleTypeDef hadc1;
DMA_HandleTypeDef hdma_adc1;
SPI_HandleTypeDef hspi1;
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_ADC1_Init(void);
static void MX_SPI1_Init(void);
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/*Variables for using FATFS.*/
FATFS fs; //file system
FIL fil; //file
FRESULT fresult; //to store the result
char buffer[1024]; //to store data
UINT br, bw; //file read/write count
FATFS *pfs;
DWORD fre_clust;
uint32_t total, free_space;
/*Variables */
uint16_t vector1[2500]={0};
uint16_t adc_data[2];
uint16_t vector2[2500]={0};
uint8_t i = 0;
uint16_t a = 0;
uint16_t mayor1 = 0;
uint16_t b = 0;
uint16_t mayor2 = 0;
//HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_data, 2);
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)
{
__NOP(); //I am using this function to use a breakpoint, and it never reaches the // //Conversion complete Callback
}
/* USER CODE END 0 */
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();
HAL_ADC_Init(&hadc1);
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_ADC1_Init();
MX_SPI1_Init();
MX_FATFS_Init();
/* USER CODE BEGIN 2 */
/* Mount SD Card */
fresult = f_mount(&fs, "", 0);
/*************** Card capacity details ********************/
/* Check free space */
f_getfree("", &fre_clust, &pfs);
total = (uint32_t)((pfs->n_fatent - 2) * pfs->csize * 0.5);
free_space = (uint32_t)(fre_clust * pfs->csize * 0.5);
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_data, 2);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
while (i<50)
{
// HAL_ADC_Start(&hadc1);
// HAL_ADC_PollForConversion(&hadc1, 50);
// a = HAL_ADC_GetValue(&hadc1);
// HAL_ADC_PollForConversion(&hadc1, 100);
// b = HAL_ADC_GetValue(&hadc1);
// HAL_ADC_Stop(&hadc1);
vector1[i]= adc_data[0];
vector2[i]= adc_data[1];
if(vector1[i] > mayor1) mayor1 = vector1[i];
if(vector2[i] > mayor2) mayor2 = vector2[i];
i++;
HAL_Delay(100);
}
2020-04-02 02:19 AM
Hello @Rubén Izquierdo ,
I made a brief comparison between my main.c file and your file. it's true that, we have the same configuration (but the order is not the same). In your main.C file, I confirm that you must remove the HAL_ADC_Init (& hadc1) just after the HAL_Init () ('already HAL_ADC_Init (& hadc1)' you will find it later in the configuration section of the ADC)
I already did the test on my side (as shown in the figure) no problem was detected.
Best regards,
Imen