[go: up one dir, main page]

0% found this document useful (0 votes)
15 views6 pages

Ex No: Interfacing With Adc Date

The document outlines an experiment to interface an Analog to Digital Converter (ADC) using embedded C code on an ARM Cortex M4 STM32F407ZG trainer kit. It details the required tools, software, and provides a code implementation for configuring the ADC and displaying its output via serial communication. The results confirm the successful verification of the ADC functions using the specified setup.

Uploaded by

abishek2003jothi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views6 pages

Ex No: Interfacing With Adc Date

The document outlines an experiment to interface an Analog to Digital Converter (ADC) using embedded C code on an ARM Cortex M4 STM32F407ZG trainer kit. It details the required tools, software, and provides a code implementation for configuring the ADC and displaying its output via serial communication. The results confirm the successful verification of the ADC functions using the specified setup.

Uploaded by

abishek2003jothi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

EX NO:

INTERFACING WITH ADC

DATE:

AIM:

To write an embedded C code & verify the functions of Analog to digital convertor(ADC) using
IAR Embedded workbench and the output using ARM cortex M4 STM32f407ZG trainer kit.

TOOLS REQUIRED:

• ARM Cortex M4 STM32f407 trainer kit.


• CRO
• Power cord
• USB Cable
• Probes and connecting wires

SOFTWARE REQUIRED:
• IAR Embedded Workbench 6.50.1.446
• Flash Loader Demo

THEORY:

 STM32F407ZG – Cortex has three 12-bits ADC channels. In Vi_STM32 syllabus board includes
two potentiometers for the analog voltage variations. The potentiometers POT1 is connected to
ADC3_IN8 that is PF10 of the controller.
 The potentiometer POT2 is connected to ADC3_IN7 that is PF9 of the controller. The ADC vating
between 0 to 4095. ADC outputs are displayed through the serial communication (P10 or P3).

PROGRAM:

#include"stm32f4xx.h"
#include"stm32f4xx_rcc.h"
#include"stm32f4xx_dma.h"
#include"stm32f4xx_usart.h"
#include"stm32f4xx_adc.h"
#include"stm32f4xx_gpio.h"
#include"misc.h"
#include"stdio.h"
IO uint32_t mb=0;
#define PUTCHAR_PROTOTYPE IOint putchar(int c);
void pinconfig()
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3,ENABLE);
GPIOF->MODER=0X000C0000;
}
void data()
{
DMA_InitTypeDef a;
a.DMA_Channel= DMA_Channel_2;
a. DMA_PeripheralBaseAddr=0x4001224C;
a.DMA_Memory0BaseAddr=(uint32_t)&mb;
a.DMA_DIR=DMA_DIR_PeripheralToMemory;
a.DMA_BufferSize=1;
a.DMA_PeripheralDataSize=DMA_PeripheralDataSize_HalfWord;
a.DMA_MemoryDataSize=DMA_MemoryDataSize_HalfWord;
a.DMA_Mode=DMA_Mode_Circular;
DMA_Init(DMA2_Stream0,&a);
DMA_Cmd(DMA2_Stream0,ENABLE);
}
void usart1(int baud)
{
USART_InitTypeDef serial;
GPIOC->MODER=0X00A00000;
GPIOC->AFR[1]=0X00007700;
serial.USART_BaudRate=baud;
serial.USART_WordLength=USART_WordLength_8b;
serial.USART_StopBits=USART_StopBits_1;
serial.USART_Parity=USART_Parity_No;
serial.USART_Mode=USART_Mode_Tx|USART_Mode_Rx;
USART_Init(USART3,&serial);
USART_Cmd(USART3,ENABLE);
}
void gpio1()
{
GPIO_InitTypeDef s;
s.GPIO_Pin=GPIO_Pin_9;
s.GPIO_Mode=GPIO_Mode_AN;
GPIO_Init(GPIOF,&s);
}
void adc1()
{
ADC_InitTypeDef b;
b.ADC_Resolution=ADC_Resolution_12b;
b.ADC_ExternalTrigConvEdge=ADC_ExternalTrigConvEdge_None;
b.ADC_ExternalTrigConv=ADC_ExternalTrigConv_T1_CC1;
b.ADC_DataAlign=ADC_DataAlign_Right;
ADC_Init(ADC3,&b);
ADC_RegularChannelConfig(ADC3,ADC_Channel_7,1,ADC_SampleTime_3Cycles);
ADC_DMARequestAfterLastTransferCmd(ADC3,ENABLE);
ADC_DMACmd(ADC3,ENABLE);
ADC_Cmd(ADC3,ENABLE);
gpio1();
}

void delay()
{
for(int i=0;i<0xff;i++)
{
}
}
int putchar(int c)
{
USART_SendData(USART3,c);
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)==RESET)
{
}
return c;
}

void main(){
pinconfig();
usart1(115200);
data();
adc1();
ADC_SoftwareStartConv(ADC3);
while(1)
{
printf("ADC VALUE is %d",mb);
delay();
}
}

Preparation / Observation 15
Experimentation 15
Result & Interpretation 15
Viva 15
Record 15
Total 75

RESULT:
Thus the embedded C code has been written and the functions of analog to digital convertor is
verified by using IAR Embedded workbench and the output is verified by ARM Cortex M4
development board kit and CRO.

You might also like