This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

About on-chip ADC of ST3434E

Hi, everyone: Does anybody has used ST3434E before? The easiset ADC gets me confused. Following is my code:


#include <ST/upsd3400.h>
#include "DATATYPES.H"
#include "ADC.h"


sfr16 ADAT      = 0x95;
sfr16 P1SFS     = 0x8e;


#define ADC_ENABLE      0x20
#define ADC_START       0x02
#define ADC_BUSY        0x01
#define ADC_WORK        (ADC_ENABLE | ADC_START)


VOID ADC_Init(VOID)
{
        P1SFS   |= 0x0101; // ADC channel 0
        //P1SFS0        = 0x01;
        //P1SFS1        = 0x01;

        ACON    = ADC_ENABLE;// ADC enable, interrupt disable, channel 0
}

WORD ADC_Read(VOID)
{
        ACON = ADC_START;
        while (!(ACON & ADC_BUSY)); // wait until ADC is not busy
        //ACON &= ~ADC_ENABLE;
        return (ADAT);
}

The bit 0 of ACON is status flag, when it is set to 1, the AD conversion completed. But it is never set!

Keil 8, JTAG debugger

Parents
  • 
    #include <ST/upsd3400.h>
    #include "DATATYPES.H"
    #include "ADC.h"
    
    
    sfr16 ADAT      = 0x95;
    sfr16 P1SFS     = 0x8e;
    
    
    #define ADC_AINTF       0x80
    #define ADC_AINTEN      0x40
    #define ADC_ENABLE      0x20
    #define ADC_START       0x02
    #define ADC_BUSY        0x01
    #define ADC_WORK        (ADC_ENABLE | ADC_START)
    
    
    VOID ADC_Init(VOID)
    {
            P1SFS   =       0x0101; // ADC channel 0
            //P1SFS0        =       0x01;
            //P1SFS1        =       0x01;
    
            //ACON  =       ADC_ENABLE;// ADC enable, interrupt disable, channel 0
    }
    
    WORD ADC_Read(VOID)
    {
            DWORD i;
            ACON    &=  0xE3;                   // choose channel 0
            ACON    |=      ADC_ENABLE;             // enable and start ADC
            for (i = 0; i < 1000000L; i++);
            ACON    |=      ADC_START;
            while (!(ACON & ADC_BUSY)); // wait until ADC is not busy
            //ACON &= ~ADC_ENABLE;
            return ADAT;
    }
    
    

    But the bit 0 of ACON is never set either.

Reply
  • 
    #include <ST/upsd3400.h>
    #include "DATATYPES.H"
    #include "ADC.h"
    
    
    sfr16 ADAT      = 0x95;
    sfr16 P1SFS     = 0x8e;
    
    
    #define ADC_AINTF       0x80
    #define ADC_AINTEN      0x40
    #define ADC_ENABLE      0x20
    #define ADC_START       0x02
    #define ADC_BUSY        0x01
    #define ADC_WORK        (ADC_ENABLE | ADC_START)
    
    
    VOID ADC_Init(VOID)
    {
            P1SFS   =       0x0101; // ADC channel 0
            //P1SFS0        =       0x01;
            //P1SFS1        =       0x01;
    
            //ACON  =       ADC_ENABLE;// ADC enable, interrupt disable, channel 0
    }
    
    WORD ADC_Read(VOID)
    {
            DWORD i;
            ACON    &=  0xE3;                   // choose channel 0
            ACON    |=      ADC_ENABLE;             // enable and start ADC
            for (i = 0; i < 1000000L; i++);
            ACON    |=      ADC_START;
            while (!(ACON & ADC_BUSY)); // wait until ADC is not busy
            //ACON &= ~ADC_ENABLE;
            return ADAT;
    }
    
    

    But the bit 0 of ACON is never set either.

Children