ADC using mmap not writing to memory

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ADC using mmap not writing to memory

655 Views
scottpicker
Contributor I

I am using a MYS-6ULX-IND board  running linux os

I am trying to write to addresses in memory using mmap for the ADC.  I have write the following code to read and write to memory for the ADC_CFG location.  The problem I an having is that it writes then it is erased immediately.  Is there a solution to make it write and save the information in memory?

    void *ADCmap;
    int fd,i;
    unsigned int ADC1_Address,CFG_Value,New_Value;
    unsigned int CFG_Settings[16] = {0,0,0,1,1,0,0,0,1,1,0,0,0,0,1,1,1};
    CFG_Value = 0;
    ADC1_Address = ADC1_BASE;
    fd = open("/dev/mem",O_RDWR);
    if (fd < 0)
    {
        perror("Open mem for ADC\n");
        return -1;
    }
    ADCmap = mmap(NULL,4096,PROT_READ | PROT_WRITE,MAP_SHARED,fd,ADC1_Address);
    //Set the config register for ADC1
    unsigned int *ADC1_CFG = (unsigned int *)(ADCmap + 0x0014);
    CFG_Value = *ADC1_CFG;
    printf("CFG Register = %u\n",CFG_Value);
    for (i = 0;i<sizeof(CFG_Settings);i++)
    {
        switch(CFG_Settings[i])
        {
        case 0:
            CFG_Value = Bit_Conversion(CFG_Value,i,"CLR");
            break;
        case 1:
            CFG_Value = Bit_Conversion(CFG_Value,i,"SET");
            break;
        }
    }
    printf("NEW CFG Value = %u\n",CFG_Value);
    *ADC1_CFG = CFG_Value;
    close(fd);
    munmap(ADCmap,4096);

Labels (1)
0 Kudos
1 Reply

516 Views
igorpadykov
NXP Employee
NXP Employee

Hi Scott

for mmap examples one can loook at memtool included in imx-test package:
www.nxp.com/lgfiles/NMG/MAD/YOCTO/imx-test-5.7.tar.gz

Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos