Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
5年后-NXP ADC无法工作_C_Microcontroller_Adc_Cpu Registers_Nxp Microcontroller - Fatal编程技术网

5年后-NXP ADC无法工作

5年后-NXP ADC无法工作,c,microcontroller,adc,cpu-registers,nxp-microcontroller,C,Microcontroller,Adc,Cpu Registers,Nxp Microcontroller,不久前,我试图在NXP的LPC3143上编程ADC,但没有成功。5年后的今天,我给自己买了一个,并用LPC4088试了试。同样的问题仍然存在于ADC!当I/O配置、GPIO、定时器和PWM像一个魔咒一样工作时,我似乎无法让它工作 我总是通过阅读。因此,在阅读了手册之后,我想到了: LPC4088 ioconfig.h LPC4088系统.h LPC4088 gpio.h LPC4088模数转换器.h main.c 以下是LPC4088快速启动板的更详细接口说明-我的外部电位计输出连接到P1.31

不久前,我试图在NXP的LPC3143上编程ADC,但没有成功。5年后的今天,我给自己买了一个,并用LPC4088试了试。同样的问题仍然存在于ADC!当I/O配置、GPIO、定时器和PWM像一个魔咒一样工作时,我似乎无法让它工作

我总是通过阅读。因此,在阅读了手册之后,我想到了:

LPC4088 ioconfig.h

LPC4088系统.h

LPC4088 gpio.h

LPC4088模数转换器.h

main.c

以下是LPC4088快速启动板的更详细接口说明-我的外部电位计输出连接到P1.31,而LED已嵌入板上:


好吧,所以我为了这件事拼命工作了10个小时,早上4:30就上床睡觉了。。。这里是-LPC4088 ADC头文件的工作示例与问题中的相同:

#include "LPC4088-ioconfig.h"
#include "LPC4088-system.h"
#include "LPC4088-gpio.h"
#include "LPC4088-adc.h"

int main(){

    IOCON_P1_13 &= !(0x67F);
    IOCON_P1_31 |= 0b011;
    IOCON_P1_31 &= !(0b11<<4);
    IOCON_P1_31 &= !(1<<7);
    IOCON_P0_23 |= 0b011;
    IOCON_P0_23 &= !(0b11<<4);
    IOCON_P0_23 &= !(1<<7); 


    PCONP |= (1<<15);    
    DIR1 |= (1<<13);
    MASK1 &= !(1<<13);


    PCONP |= (1<<12);
    INTEN &= !(0x1FF);
    CR &= !(0x7<<24);
    CR &= !(1<<16);


    while(1){
        CR |= (1<<21);
        CR |= (0x1<<24);
        while( (STAT & (1<<0) ) == 0x0 );
        CR &= !(0x1<<24);

        unsigned int result = 0;
        result = ( (DR0 & 0xFFF0) >> 4);

        CR &= (1<<21);      

        if (result > 0x7FF){
            SET1 |= (1<<13);
        }
        else{
            CLR1 |= (1<<13);
        }
    }       
}

LPC中的示例更简单。我打赌这会对你们中的一些人有所帮助。。。我打算用这些例子来打开我的GIT,为所有的外围设备。但现在我只知道如何操作ioconfig、gpio、定时器、pwm和adc。

您是否出于某种原因反对赋值运算符?对不起,我不明白您的意思。你能解释一下吗?你对这项提案的支持率比你高。我会修正它的可读性。停止多次重击同一个易失性寄存器。读取一次,多次修改该值,然后写入一次。它不是一个普通的变量,它是易变的,因此编译器无法优化您的愚蠢行为。
//register definitions for system & clock peripheral
//used to turn on peripherals

#define PCONP          (*((volatile unsigned int *) 0x400FC0C4))
//register definitions for GPIO peripheral 
//only port 1

#define DIR1           (*((volatile unsigned int *) 0x20098020))    
#define MASK1          (*((volatile unsigned int *) 0x20098030))
#define PIN1           (*((volatile unsigned int *) 0x20098034))
#define SET1           (*((volatile unsigned int *) 0x20098038))
#define CLR1           (*((volatile unsigned int *) 0x2009803C))
//register definitions for ADC peripheral

#define CR             (*((volatile unsigned int *) 0x40034000))
#define GDR            (*((volatile unsigned int *) 0x40034004))
#define INTEN          (*((volatile unsigned int *) 0x4003400C))

#define DR0            (*((volatile unsigned int *) 0x40034010))
#define DR1            (*((volatile unsigned int *) 0x40034014))
#define DR2            (*((volatile unsigned int *) 0x40034018))
#define DR3            (*((volatile unsigned int *) 0x4003401C))
#define DR4            (*((volatile unsigned int *) 0x40034020))
#define DR5            (*((volatile unsigned int *) 0x40034024))
#define DR6            (*((volatile unsigned int *) 0x40034028))
#define DR7            (*((volatile unsigned int *) 0x4003402C))

#define STAT           (*((volatile unsigned int *) 0x40034030))
#define TRM            (*((volatile unsigned int *) 0x40034034))
#include "LPC4088-ioconfig.h"
#include "LPC4088-system.h"
#include "LPC4088-gpio.h"
#include "LPC4088-adc.h"

int main(){

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

    //we set P1.13 (port 1, pin 13) as GPIO, no pull-up, no hysteresis, not inverted, standard, push-pull
    IOCON_P1_13 &= !(0x67F);

    //we turn on GPIO peripheral
    PCONP |= (1<<15);    

    //set P1.13 as an output GPIO
    DIR1 |= (1<<13);

    //setting a mask for pin P1.13
    MASK1 &= !(1<<13);

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

    //configure pin P1.31 as an input ADC0_IN5 (channel 5)
    IOCON_P1_31 |= 0b011;

    //we disable pullup or pulldown resistors on pin P1.31
    IOCON_P1_31 &= !(0x3<<4);

    //we configure pin P1.31 for ADMODE
    IOCON_P1_31 &= !(1<<7);

    //we turn on the ADC peripheral
    PCONP |= (1<<12);

    //we divide PCLK delimo with 99+1=100 (only for precaution)
    CR |= (99<<8);

    //we start the ADC
    CR |= (1<<21);

    //we disable ADC interrupts
    INTEN &= !(0x1FF);

    //we choose chanel 5 which is the only one that we choose 
    CR &= !(0xFF);
    CR |= (1<<5);

    //before choosing "burst mode" we need to turn off the conversion
    CR &= !(0x7<<24);

    //we choose "burst mode" - conversion starts and is continuous
    CR |= (1<<16);

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


    while(1){

        //we wait for the conversion to finish and we save the result
        //we right-shift because value is stored in DR5 bits 15:4!

        while( (DR5 & (1<<31) ) != (1<<31) );
        int result = ( (DR5 & 0xFF0) >> 4);

        //12-bit has a max value of 0xFFF - we compare result to the half of this value - 0x7FF.

        if (result >= 0x7FF){
            //turn on an LED on pin P1.13
            SET1 |= (1<<13);
        }
        else{
            //turn off an LED on pin P1.13
            CLR1 |= (1<<13);
        }
    }       
}
#include "LPC4088-ioconfig.h"
#include "LPC4088-system.h"
#include "LPC4088-gpio.h"
#include "LPC4088-adc.h"

int main(){

    IOCON_P1_13 &= !(0x67F);
    IOCON_P1_31 |= 0b011;
    IOCON_P1_31 &= !(0b11<<4);
    IOCON_P1_31 &= !(1<<7);
    IOCON_P0_23 |= 0b011;
    IOCON_P0_23 &= !(0b11<<4);
    IOCON_P0_23 &= !(1<<7); 


    PCONP |= (1<<15);    
    DIR1 |= (1<<13);
    MASK1 &= !(1<<13);


    PCONP |= (1<<12);
    INTEN &= !(0x1FF);
    CR &= !(0x7<<24);
    CR &= !(1<<16);


    while(1){
        CR |= (1<<21);
        CR |= (0x1<<24);
        while( (STAT & (1<<0) ) == 0x0 );
        CR &= !(0x1<<24);

        unsigned int result = 0;
        result = ( (DR0 & 0xFFF0) >> 4);

        CR &= (1<<21);      

        if (result > 0x7FF){
            SET1 |= (1<<13);
        }
        else{
            CLR1 |= (1<<13);
        }
    }       
}