I m quite new with using ADC. I am using an external ADC MAX144 to get sensor data using STM32L452RE. I am using both channels of this ADC for two sensors. ADC is continuously sending data and I want to read it.
datasheet of ADC is here
what I am doing is:
- created a 2 byte buffer
- i am using DMA for both spi and uart
- receiving data in buffer with HAL_SPI_Receive_DMA()
- transmitting data over usart using HAL_UART_Transmit_DMA()
code that i have made is given below:
#include "main.h"
#include "stm32l4xx_hal.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private variables ---------------------------------------------------------*/
SPI_HandleTypeDef hspi3;
DMA_HandleTypeDef hdma_spi3_rx;
TIM_HandleTypeDef htim1;
UART_HandleTypeDef huart3;
DMA_HandleTypeDef hdma_usart3_tx;
/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------
------*/
static uint8_t readBuffer[2];
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_USART3_UART_Init(void);
static void MX_SPI3_Init(void);
static void MX_TIM1_Init(void);
/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE END PFP */
/* USER CODE BEGIN 0 */
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi){
while(1);
}
void UART_DMATransmitCplt(DMA_HandleTypeDef *hdma){
while(1);
}
`enter code here`void delay(uint16_t delay)
{
__HAL_TIM_SET_COUNTER(&htim1,0);
while(__HAL_TIM_GET_COUNTER(&htim1) < delay);
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
*
* @retval None
*/
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();
/* 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_USART3_UART_Init();
MX_SPI3_Init();
MX_TIM1_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_1, SET);
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
HAL_Delay(80);
HAL_SPI_Receive_DMA(&hspi3, readBuffer, 2);
HAL_UART_Transmit_DMA(&huart3, readBuffer, 2);
}
/* USER CODE END 3 */
}
I am stuck in this problem for the last two weeks. any guides in this regards will be highly appreciated.
regards.
These Callbacks doesn't work
The Callbacks are called directly from the Interrupt routines. If you put a while(1) in there the interrupt will never finish.
Make a first try without the DMA functions.
And see if your SPI ready ind USART writing works. As a second step you could try to setup the DMA transfer.