【ARM】ADC·FS2410 digital-to-analog conversion

Publisher:技术掌门Latest update time:2021-07-13 Source: eefocusKeywords:ARM  ADC  FS2410 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Development Environment

1. Hardware platform: FS2410

2. Host: Ubuntu 12.04


ADC Register Configuration

1. Initialize ADC (ADCCON)

Set the prescaler, prescaler factor, select the A/D conversion channel, select normal mode and start the conversion


2. Determine whether the conversion is completed (ADCCON[5])


3. Read conversion results (ADCDATn)

Initialization of the serial port


See "Serial Port Communication FS2410": http://infohacker.blog.51cto.com/6751239/1223137


source code

 //adc.c

#include "2410addr.h" //header file, including register settings

                                      

void putc(char ch) //send character

{

    while(!(rUTRSTAT0 & 0X2)); //Judge whether the send buffer is empty

                                           

    rUTXH0 = ch; //send

}

                                      

char getc(void) //Receive character

{

    while(!(rUTRSTAT0 & 0X1)); //Judge whether the receiving buffer is empty

                                          

    return rURXH0; //receive

}

                                      

void putstr(char *str) //Send string

{

    while(*str != '')

    {

        if(*str == 'n')

        {

            putc('n');

            putc('r');

        }

        else

            putc(*str);

                                              

        str++;

    }

}

                                      

void wait(long long max) //delay function

{

    for(; max > 0; max--)

        ;

}

                                      

void itoa(unsigned long value) // character conversion

    unsigned long temp;

    int i, flag = 0;

    char data[4];

                                          

    for(i = 0; i < 4; i++) // Clear the array

        data[i] = '';

                                      

    for(i = 0; i < 3; i++)

    {

        temp = (value >> 4 * i) & 0xf;

                                              

        if(temp < 10)

            data[2 - i] = '0' + temp;

        else

        { 

            if(temp <= 0xf)

                data[2 - i] = 'a' + temp - 10;

        }

    }

                                      

    putstr(" Value of AIN0 is 0x");

    putstr(data);

                                          

    putstr("r");

    putstr("n");

}

                                      

int main(void)

{

    rGPHCON = rGPHCON & ~(0xf << 4) | (0xa << 4); //Configure RDX0 and TDX0

    rGPHUP = 0X0c; //Set the pull-up resistor

                                      

    rUFCON0 = 0;    //不用FIFO

    rUMCON0 = 0; //No flow control required

    rULCON0 = 0X3; //8-bit data, 1 stop bit, no parity, normal mode

    rUCON0 = 0X5; //Clock source bit PCLK, interrupt mode is query

    rUBRDIV0 = ((int)(50000000 / 115200 / 16) - 1); //Set the baud rate to 115200

    rADCCON = 0x4c41; //Initialize ADC

                                      

    putstr("nThis is ADC test:n");

                                      

    unsigned long temp = 0;

                                          

    while(1)

    {

        while((rADCCON & (1 << 15)) == 0); //Judge whether the conversion is completed

                                      

        temp = rADCDAT0; //Read conversion value

        temperature(temp);

                                              

        rADCCON = 0x4c41; //Restart ADC

        wait(200000);

    }

                                      

    return 0;

}


 //start.S


.text

.global _start

_start:

#define WATCHDOG 0x53000000

    ldr r0, =WATCHDOG

    mov r1, #0

    str r1, [r0]

                                  

    ldr sp, =1024*4

    bl main

                                  

loop:

    b loop


//Makefile


adc.bin: start.S adc.c

    arm-linux-gcc -c start.S -o start.o

    arm-linux-gcc -c adc.c -o adc.o

    arm-linux-ld -Ttext 0x30008000 start.o adc.o -o adc

    arm-linux-objcopy -O binary -S adc adc.bin

                                

clean:

    rm -f *.o adc.bin


Compile and link

 OK, success!

Keywords:ARM  ADC  FS2410 Reference address:【ARM】ADC·FS2410 digital-to-analog conversion

Previous article:【ARM】gpio·gpio of arm architecture
Next article:【ARM】Serial communication·FS2410·Bare metal UART

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号