AnsweredAssumed Answered

ADC using mmap not writing to memory

Question asked by Scott Picker on Feb 5, 2018
Latest reply on Feb 6, 2018 by igorpadykov

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++)
        case 0:
            CFG_Value = Bit_Conversion(CFG_Value,i,"CLR");
        case 1:
            CFG_Value = Bit_Conversion(CFG_Value,i,"SET");
    printf("NEW CFG Value = %u\n",CFG_Value);
    *ADC1_CFG = CFG_Value;