AnsweredAssumed Answered

ADC cannot read multiple channels ..

Question asked by Raider E on Dec 16, 2016
Latest reply on Jan 22, 2017 by T J

Hi Everyone,

 

I've been trying  to read multiple ADC channels(ADC_CHANNEL_1 and ADC_CHANNEL_0) . Would you please tel me whats wrong with my code.  I came to know that I will have to use DMA and the settings seem all alright to me!. Would it be possible to avoid using DMA. I just need to read the channels once in every loop. I checked some the cubemx examples but didnt help me to understand whats wrong. 

 

I am printing the values I read to my LCD screen and at the moment reads : value[0]=0.0x and value[1]=0!. When I use the normal ADC reading I can read value[0]=1.3V and value[1]=1.3.  My channel 0 is connected o 1.3 V and channel 1 is not connected and supposed to read 0V. Also i am onot sure whats woring with chnnl 1 if change its rank to 1 instead of 2 and try to read it using a normal HAL_ADC_GetValue I get varying values changing on screen from .5 to 2.5V!!. Please help. 

 

Main.c

 

/**
******************************************************************************
***
*/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32f7xx_hal.h"
#include "cmsis_os.h"
#include "OLED.h"
#include "AsciiLib.h"
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/
ADC_HandleTypeDef hadc1;

DMA_HandleTypeDef hdma_adc1;

CAN_HandleTypeDef hcan1;

DAC_HandleTypeDef hdac;

SPI_HandleTypeDef hspi1;

osThreadId defaultTaskHandle;

ADC_ChannelConfTypeDef sConfig;

/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
uint32_t val_dac, value[2];
//__IO uint16_t value[2];
uint16_t x_position1, y_position1, screen_width1;
uint8_t Byte_num = 0x0, LD1=0x0;
uint8_t data[10]="";
float val_disp;
int x11=0;
uint8_t can_message[1];
float Dic_val[10];
uint8_t Channel_n[2];


/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void Error_Handler(void);
static void MX_GPIO_Init(void);
static void MX_CAN1_Init(void);
static void MX_SPI1_Init(void);
static void MX_ADC1_Init(void);
static void MX_DMA_Init(void);
static void MX_DAC_Init(void);
void StartDefaultTask(void const * argument);


void OLEDwriteCommand(uint8_t c);
void OLEDwriteData(uint8_t c);
void OLEDLine(int16_t x, int16_t y, int16_t w, uint16_t color);
void OLEDinit();
/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/

/* USER CODE END PFP */

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

int main(void)
{

/* USER CODE BEGIN 1 */
x_position1=0;
y_position1=0;
screen_width1=128;
/* USER CODE END 1 */

/* MCU Configuration----------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* Configure the system clock */
SystemClock_Config();

/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_CAN1_Init();
MX_SPI1_Init();
MX_ADC1_Init();
MX_DMA_Init();
MX_DAC_Init();
OLEDinit();

/* USER CODE BEGIN 2 */
for(y_position1=0;y_position1<128;y_position1++){
OLEDLine(x_position1,y_position1,screen_width1,BLACK);
}
ILI9325_TextFont(0,0,"Voltage:",BLUE,BLACK,FONT8x8_table);
ILI9325_TextFont(0,30,"Pressure:",BLUE,BLACK,FONT8x8_table);
ILI9325_TextFont(0,50,"CAN BUS:",BLUE,BLACK,FONT8x8_table);

HAL_CAN_Receive_IT(&hcan1, CAN_FIFO0);
/* USER CODE END 2 */

/* USER CODE BEGIN RTOS_MUTEX */
/* add mutexes, ... */
/* USER CODE END RTOS_MUTEX */

/* USER CODE BEGIN RTOS_SEMAPHORES */
/* add semaphores, ... */
/* USER CODE END RTOS_SEMAPHORES */

/* USER CODE BEGIN RTOS_TIMERS */
/* start timers, add new ones, ... */
/* USER CODE END RTOS_TIMERS */

/* Create the thread(s) */
/* definition and creation of defaultTask */
// osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
// defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* USER CODE END RTOS_THREADS */

/* USER CODE BEGIN RTOS_QUEUES */
/* add queues, ... */
/* USER CODE END RTOS_QUEUES */

/* Start scheduler */
// osKernelStart();

/* We should never get here as control is now taken by the scheduler */

/* Infinite loop */
/* USER CODE BEGIN WHILE */
// HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&value[0], 2);
// HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&value, 4);
char Channel_ADC[13];

while (1)
{
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */
/////////////////////////////DAC
HAL_DAC_Init(&hdac);
HAL_DAC_Start(&hdac, DAC_CHANNEL_1);
val_dac=100;
HAL_DAC_SetValue(&hdac,DAC_CHANNEL_1,DAC_ALIGN_8B_R,val_dac);

///////////////////////////////ADC
//HAL_ADC_Start(&hadc1);
HAL_ADC_Start_DMA(&hadc1, value, 4);
// sprintf(Channel_ADC, "%s%s", "ADC_CHANNEL_", "1");
// sConfig.Channel = ADC_CHANNEL_1;
// HAL_ADC_Start(&hadc1);
// HAL_ADC_PollForConversion(&hadc1,1000);
// value[0]= HAL_ADC_GetValue(&hadc1);
// //HAL_ADC_PollForConversion(&hadc1,1000);
// value[1]= HAL_ADC_GetValue(&hadc1);
//value[1]= HAL_ADC_GetValue(&hadc1);

// HAL_ADC_Start_DMA(&hadc1,value,2);
switch(Byte_num & 0xF0) {
case 0x10:
if ((Byte_num & 0x0F)==0){
//val_disp=(value[Byte_num & 0x0F]/4096.0f)*3.3;
val_disp=(value[0]/4096.0f)*3.3;
Dic_val[Byte_num & 0x0F]=val_disp;
sprintf(data, "%.2f", val_disp);
ILI9325_TextFont(0,60,data,WHITE,BLACK,FONT8x8_table);

}
else if(((Byte_num & 0x0F)==1)) {
//val_disp=(value[Byte_num & 0x0F]/4096.0f)*3.3;
val_disp=(value[1]/4096.0f)*3.3;
Dic_val[Byte_num & 0x0F]=val_disp;
sprintf(data, "%.2f", val_disp);
ILI9325_TextFont(0,80,data,RED,BLACK,FONT8x8_table);

}


case 0x20 :
break;


}


// HAL_ADC_Start_DMA(&hadc1,(uint32_t*)&value,2);

// value= HAL_ADC_GetValue(&hadc1);

// val_disp=(value[0]/4096.0f)*3.3;
// Dic_val[0]=val_disp;
// sprintf(data, "%.2f", val_disp);
// ILI9325_TextFont(0,15,data,WHITE,BLACK,FONT8x8_table);

}
/* USER CODE END 3 */

}

/** System Clock Configuration
*/
void SystemClock_Config(void)
{

RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;

/**Configure the main internal regulator output voltage
*/
__HAL_RCC_PWR_CLK_ENABLE();

__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 8;
RCC_OscInitStruct.PLL.PLLN = 192;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}

/**Activate the Over-Drive mode
*/
if (HAL_PWREx_EnableOverDrive() != HAL_OK)
{
Error_Handler();
}

/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;

if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6) != HAL_OK)
{
Error_Handler();
}

/**Configure the Systick interrupt time
*/
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

/**Configure the Systick
*/
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
}

/* ADC1 init function */
static void MX_ADC1_Init(void)
{

ADC_ChannelConfTypeDef sConfig;

/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
*/
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.ScanConvMode = ENABLE;
hadc1.Init.ContinuousConvMode = ENABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 2;
hadc1.Init.DMAContinuousRequests = ENABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}

/**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
*/
sConfig.Channel = ADC_CHANNEL_0;
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}

sConfig.Channel = ADC_CHANNEL_1;
sConfig.Rank = 2;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
}

/* CAN1 init function */
static void MX_CAN1_Init(void)
{

CAN_FilterConfTypeDef sFilterConfig;
static CanTxMsgTypeDef TxMessage;
static CanRxMsgTypeDef RxMessage;

/*##-1- Configure the CAN peripheral #######################################*/
hcan1.Instance = CAN1;
hcan1.pTxMsg = &TxMessage;
hcan1.pRxMsg = &RxMessage;

hcan1.Init.Prescaler = 12;
hcan1.Init.Mode = CAN_MODE_NORMAL;
hcan1.Init.SJW = CAN_SJW_1TQ;
hcan1.Init.BS1 = CAN_BS1_5TQ;
hcan1.Init.BS2 = CAN_BS2_2TQ;
hcan1.Init.TTCM = DISABLE;
hcan1.Init.ABOM = DISABLE;
hcan1.Init.AWUM = DISABLE;
hcan1.Init.NART = DISABLE;
hcan1.Init.RFLM = DISABLE;
hcan1.Init.TXFP = DISABLE;
if (HAL_CAN_Init(&hcan1) != HAL_OK)
{
Error_Handler();
}

// Filter Configuration
/*##-2- Configure the CAN Filter ###########################################*/
sFilterConfig.FilterNumber = 0;
sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
sFilterConfig.FilterIdHigh = 0x321;
sFilterConfig.FilterIdLow = 0x0000;
sFilterConfig.FilterMaskIdHigh = 0x0000;
sFilterConfig.FilterMaskIdLow = 0x0000;
sFilterConfig.FilterFIFOAssignment = CAN_FIFO0;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.BankNumber = 0;
HAL_CAN_ConfigFilter(&hcan1, &sFilterConfig);
// if(HAL_CAN_ConfigFilter(&hcan1, &sFilterConfig) != HAL_OK)
// {
// /* Filter configuration Error */
// Error_Handler();
// }

/*##-3- Configure Transmission process #####################################*/
hcan1.pTxMsg->StdId = 0x322;
hcan1.pTxMsg->ExtId = 0x01;
hcan1.pTxMsg->RTR = CAN_RTR_DATA;
hcan1.pTxMsg->IDE = CAN_ID_STD;
hcan1.pTxMsg->DLC = 1;

}

/* DAC init function */
static void MX_DAC_Init(void)
{

DAC_ChannelConfTypeDef sConfig;

/**DAC Initialization
*/
hdac.Instance = DAC;
if (HAL_DAC_Init(&hdac) != HAL_OK)
{
Error_Handler();
}

/**DAC channel OUT1 config
*/
sConfig.DAC_Trigger = DAC_TRIGGER_NONE;
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
if (HAL_DAC_ConfigChannel(&hdac, &sConfig, DAC_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}

}

/* SPI1 init function */
static void MX_SPI1_Init(void)
{

hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_1LINE;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 7;
hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}

}

 

/** Configure pins as
* Analog
* Input
* Output
* EVENT_OUT
* EXTI
*/
static void MX_GPIO_Init(void)
{

GPIO_InitTypeDef GPIO_InitStruct;

/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();

HAL_GPIO_WritePin(GPIOG, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2, GPIO_PIN_RESET);

/*Configure GPIO pins : RS_Pin DC_Pin CS_Pin */
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);


/*Configure GPIO pin : PC13 */
GPIO_InitStruct.Pin = GPIO_PIN_13;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

/*Configure GPIO pin : PB7 */
GPIO_InitStruct.Pin = GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_RESET);

/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);

}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/* StartDefaultTask function */
void StartDefaultTask(void const * argument)
{

/* USER CODE BEGIN 5 */
/* Infinite loop */
for(;;)
{
osDelay(1);
}
/* USER CODE END 5 */
}

/**
* @brief Period elapsed callback in non blocking mode
* @note This function is called when TIM1 interrupt took place, inside
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
* a global variable "uwTick" used as application time base.
* @param htim : TIM handle
* @retval None
*/
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
/* USER CODE BEGIN Callback 0 */

/* USER CODE END Callback 0 */
if (htim->Instance == TIM1) {
HAL_IncTick();
}
/* USER CODE BEGIN Callback 1 */

/* USER CODE END Callback 1 */
}

/**
* @brief This function is executed in case of error occurrence.
* @param None
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler */
/* User can add his own implementation to report the HAL error return state */
while(1)
{
}
/* USER CODE END Error_Handler */
}

#ifdef USE_FULL_ASSERT

/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */

}

#endif

/**
* @}
*/


//////////////////////////////////////////////////////////////////
void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef* CanHandle)
{
if ((CanHandle->pRxMsg->StdId == 0x321)&&(CanHandle->pRxMsg->IDE == CAN_ID_STD) && (CanHandle->pRxMsg->DLC == 1))
{
// HAL_CAN_IRQHandler(&hcan1);
// hcan1->pRxMsg->Data[0];
// sprintf(data, "%d", hcan1->pRxMsg->Data[0]);
// Byte_num=hcan1->pRxMsg->Data[0];
// ILI9325_TextFont(120,50,data,RED,BLACK,FONT8x8_table);

Byte_num=CanHandle->pRxMsg->Data[0]; //address
// sprintf(data, "%d", hcan1.pRxMsg->Data[0]);
// ILI9325_TextFont(120,50,data,RED,BLACK,FONT8x8_table);
//HAL_CAN_Receive_IT(&hcan1, CAN_FIFO0);
}
RxIntEnable(CanHandle);

}

void RxIntEnable(CAN_HandleTypeDef *CanHandle) {
if(CanHandle->State == HAL_CAN_STATE_BUSY_TX)
CanHandle->State = HAL_CAN_STATE_BUSY_TX_RX;
else {
CanHandle->State = HAL_CAN_STATE_BUSY_RX;

/* Set CAN error code to none */
CanHandle->ErrorCode = HAL_CAN_ERROR_NONE;

/* Enable Error warning Interrupt */
__HAL_CAN_ENABLE_IT(CanHandle, CAN_IT_EWG);

/* Enable Error passive Interrupt */
__HAL_CAN_ENABLE_IT(CanHandle, CAN_IT_EPV);

/* Enable Bus-off Interrupt */
__HAL_CAN_ENABLE_IT(CanHandle, CAN_IT_BOF);

/* Enable Last error code Interrupt */
__HAL_CAN_ENABLE_IT(CanHandle, CAN_IT_LEC);

/* Enable Error Interrupt */
__HAL_CAN_ENABLE_IT(CanHandle, CAN_IT_ERR);
}

// Enable FIFO 0 message pending Interrupt
__HAL_CAN_ENABLE_IT(CanHandle, CAN_IT_FMP0);
}
////////////////////////////////////////////////////////////////
//}
//
// /* Receive */
// if(HAL_CAN_Receive_IT(hcan1, CAN_FIFO0) != HAL_OK)
// {
// /* Reception Error */
// Error_Handler();
// }
//}
/**
* @}
*/

static void MX_DMA_Init(void)
{
/* DMA controller clock enable */
__HAL_RCC_DMA2_CLK_ENABLE();

/* DMA interrupt init */
/* DMA2_Stream0_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn);

}

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

 

 

 

 

 

 

.......HAL_msp

 

void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
{

GPIO_InitTypeDef GPIO_InitStruct;
if(hadc->Instance==ADC1)
{
/* USER CODE BEGIN ADC1_MspInit 0 */

/* USER CODE END ADC1_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_ADC1_CLK_ENABLE();

/**ADC1 GPIO Configuration
PA0/WKUP ------> ADC1_IN0
PA1 ------> ADC1_IN1
*/
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/* USER CODE BEGIN ADC1_MspInit 1 */

/* USER CODE END ADC1_MspInit 1 */
/* Peripheral DMA init*/

hdma_adc1.Instance = DMA2_Stream0;
hdma_adc1.Init.Channel = DMA_CHANNEL_0;
hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
hdma_adc1.Init.Mode = DMA_CIRCULAR;
hdma_adc1.Init.Priority = DMA_PRIORITY_LOW;
hdma_adc1.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
hdma_adc1.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
hdma_adc1.Init.MemBurst = DMA_MBURST_SINGLE;
hdma_adc1.Init.PeriphBurst = DMA_PBURST_SINGLE;
if (HAL_DMA_Init(&hdma_adc1) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(hadc,DMA_Handle,hdma_adc1);
}

}

void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
{

if(hadc->Instance==ADC1)
{
/* USER CODE BEGIN ADC1_MspDeInit 0 */

/* USER CODE END ADC1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_ADC1_CLK_DISABLE();

/**ADC1 GPIO Configuration
PA0/WKUP ------> ADC1_IN0
PA1 ------> ADC1_IN1
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|GPIO_PIN_1);

/* Peripheral DMA DeInit*/
HAL_DMA_DeInit(hadc->DMA_Handle);


// __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc1);
}
/* USER CODE BEGIN ADC1_MspDeInit 1 */

/* USER CODE END ADC1_MspDeInit 1 */

}

 

 

HAL_IT:

/**
******************************************************************************

 

******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f7xx_hal.h"
#include "stm32f7xx.h"
#include "stm32f7xx_it.h"
#include "cmsis_os.h"
#include "OLED.h"
#include "AsciiLib.h"

/* USER CODE BEGIN 0 */
extern CAN_HandleTypeDef hcan1;

/* USER CODE END 0 */

/* External variables --------------------------------------------------------*/
extern DMA_HandleTypeDef hdma_adc1;
extern CAN_HandleTypeDef hcan1;

extern TIM_HandleTypeDef htim1;

extern void MX_CAN1_Init(void);
extern void OLEDwriteCommand(uint8_t c);
extern void OLEDwriteData(uint8_t c);
extern void OLEDLine(int16_t x, int16_t y, int16_t w, uint16_t color);
extern void OLEDinit();
extern uint8_t Byte_num;
extern uint8_t data[10];
extern uint8_t LD1;
/******************************************************************************/
/* Cortex-M7 Processor Interruption and Exception Handlers */
/******************************************************************************/

/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
/* USER CODE BEGIN SysTick_IRQn 0 */

/* USER CODE END SysTick_IRQn 0 */
osSystickHandler();
/* USER CODE BEGIN SysTick_IRQn 1 */

/* USER CODE END SysTick_IRQn 1 */
}

/******************************************************************************/
/* STM32F7xx Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_stm32f7xx.s). */
/******************************************************************************/

/**
* @brief This function handles CAN1 RX0 interrupts.
*/
void CAN1_RX0_IRQHandler(void)
{
/* USER CODE BEGIN CAN1_RX0_IRQn 0 */
// HAL_CAN_Receive(&hcan1,CAN_FIFO0,1);
//HAL_CAN_Receive_IT(&hcan1, CAN_FIFO0);
HAL_CAN_IRQHandler(&hcan1);
// if ((hcan1.pRxMsg->StdId == 0x321)&&(hcan1.pRxMsg->IDE == CAN_ID_STD) && (hcan1.pRxMsg->DLC == 1))
// {

// HAL_CAN_Receive_IT(&hcan1,CAN_FIFO0);

/* USER CODE END CAN1_RX0_IRQn 0 */
HAL_CAN_IRQHandler(&hcan1);
/* USER CODE BEGIN CAN1_RX0_IRQn 1 */

/* USER CODE END CAN1_RX0_IRQn 1 */
}

/**
* @brief This function handles TIM1 update interrupt and TIM10 global interrupt.
*/
void TIM1_UP_TIM10_IRQHandler(void)
{
/* USER CODE BEGIN TIM1_UP_TIM10_IRQn 0 */

/* USER CODE END TIM1_UP_TIM10_IRQn 0 */
HAL_TIM_IRQHandler(&htim1);
/* USER CODE BEGIN TIM1_UP_TIM10_IRQn 1 */

/* USER CODE END TIM1_UP_TIM10_IRQn 1 */
}

/**
* @brief This function handles EXTI line[15:10] interrupts.
*/
void EXTI15_10_IRQHandler(void)
{
/* USER CODE BEGIN EXTI15_10_IRQn 0 */
for (int ii=0;ii<50000;ii++){

}

if (LD1==0x0){
LD1=0x1;
}
else {
LD1=0x0;

}
/* Set the data to be transmitted */
hcan1.pTxMsg->Data[0] = LD1;
hcan1.pTxMsg->Data[1] = 0xAD;
HAL_CAN_Transmit(&hcan1, 10);
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);

/* USER CODE END EXTI15_10_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);
/* USER CODE BEGIN EXTI15_10_IRQn 1 */

/* USER CODE END EXTI15_10_IRQn 1 */
}

/**
* @brief This function handles DMA2 stream0 global interrupt.
*/
void DMA2_Stream0_IRQHandler(void)
{
/* USER CODE BEGIN DMA2_Stream0_IRQn 0 */

/* USER CODE END DMA2_Stream0_IRQn 0 */
HAL_DMA_IRQHandler(&hdma_adc1);
/* USER CODE BEGIN DMA2_Stream0_IRQn 1 */

/* USER CODE END DMA2_Stream0_IRQn 1 */
}

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Outcomes