2019-01-28 06:07 AM
#include <stdio.h>
#include <stdint.h>
#include "stm32l1xx.h"
void TIM3_IRQHandler(void);
uint32_t Channel_1=0;
void TIM3_IRQHandler(void) %Interrupt every 1 second%
{
TIM3->SR&=~TIM_SR_UIF; %Clear Flag%
ADC1->CR2|=ADC_CR2_SWSTART; %ADC Regular Start%
GPIOB->ODR^=GPIO_ODR_ODR_6; %Check if interrupt is working%
}
int main(void)
{
RCC->AHBENR|= RCC_AHBENR_GPIOAEN; %Clock Enable for PA0 ADC%
RCC->AHBENR|= RCC_AHBENR_GPIOBEN; %Clock Enable for PB6 and PB7%
GPIOB->MODER |= GPIO_MODER_MODER6_0; %Configuration as Output PB6%
GPIOB->OTYPER &= ~GPIO_MODER_MODER6;
GPIOB->OSPEEDR &= ~GPIO_OSPEEDER_OSPEEDR6;
GPIOB->PUPDR &= ~GPIO_PUPDR_PUPDR6;
GPIOB->BSRRL |= GPIO_BSRR_BS_6;
GPIOB->MODER |= GPIO_MODER_MODER7_0; %Configuration as Output PB7%
GPIOB->OTYPER &= ~GPIO_MODER_MODER7;
GPIOB->OSPEEDR &= ~GPIO_OSPEEDER_OSPEEDR7;
GPIOB->PUPDR &= ~GPIO_PUPDR_PUPDR7;
GPIOB->BSRRH |= GPIO_BSRR_BR_7;
GPIOA->MODER |= GPIO_MODER_MODER0; %Configuration as analog PA0%
GPIOA->OTYPER &= ~GPIO_MODER_MODER0;
GPIOA->OSPEEDR &= ~GPIO_OSPEEDER_OSPEEDR0;
GPIOA->PUPDR &= ~GPIO_PUPDR_PUPDR0;
RCC->APB1ENR|= RCC_APB1ENR_TIM3EN;
TIM3->PSC=31999;
TIM3->ARR=1000;
TIM3->DIER|= TIM_DIER_UIE;
TIM3->CR1|=TIM_CR1_CEN;
NVIC_EnableIRQ(TIM3_IRQn);
NVIC_SetPriority(TIM3_IRQn,1);
RCC->APB2ENR|=RCC_APB2ENR_ADC1EN; %Enable ADC Clock%
ADC1->CR2&=~ADC_CR2_ADON; %Turn OFF ADC%
while((ADC1->SR&ADC_SR_ADONS)){}; %Wait for turn off%
ADC1->CR1|=ADC_CR1_SCAN; %Set Scan Mode%
ADC1->CR2 |= ADC_CR2_EOCS; %End of conversion flag set%
ADC1->SQR1|= ADC_SQR1_L_0; %One Conversion%
ADC1->SMPR3=0x3; %24 cycles sampling%
ADC1->SQR5&=0x00; %Rank 1 for PA0%
ADC1->CR2|=ADC_CR2_ADON; %Turn ON ADC%
while(!(ADC1->SR&ADC_SR_ADONS)){}; %Wait for Turn ON%
while(1)
{
while(!(ADC1->SR&ADC_SR_EOC)){};
GPIOB->ODR^=GPIO_ODR_ODR_7;
Channel_1=ADC1->DR;
}
return 0;
}
Timer Interrupt works which is indicated by blinking of LED PB6 but ADC is not working PB7 not blinking. Please help