ADC using DPPI along with eeprom

Hi, am using the nrf52dk with nrf52832, nrf coonect sdk 2.5.1/ toolchain 2.5.2 and am building a prototype to aquire the signal from the ckp and cmp sensor in the car when its cranking to start and in order to do that am using the adc sample in the DPPI mode in order to aquire the 8000 samples for 1 channel then stop and save the data in the eeprom using the i2c.

the problem its that i cant figure it out how to save it in the eeprom using the i2c because its sends me an error and it cant write to the eeprom. 

Any suggestions how can i do that? 

I am posting my code 

case NRFX_SAADC_EVT_DONE:

            /* STEP 5.3 - Buffer has been filled. Do something with the data and proceed */
            int64_t average = 0;
            int16_t max = INT16_MIN;
            int16_t min = INT16_MAX;
            int16_t counter = 0x0000;//doy de alta el contador
            int16_t current_value; 
            int8_t high_byte = 0x00; //doy de alta los contadores que van a ir en la direeccion de la eeprom
            int8_t low_byte = 0x00;
            int ret;
            int8_t highbyte_current_value;
            int8_t lowbyte_current_value;
            for(int i=0; i < p_event->data.done.size; i++){
            
            high_byte=((counter>>8)&0xff);  //divido las direcciones de 8000 posiciones en el array en 2
            low_byte=(counter&0xff);
                current_value = ((int16_t *)(p_event->data.done.p_buffer))[i];
                highbyte_current_value=((current_value>>8)&0xff);
                lowbyte_current_value= (current_value&0xff);
               //LOG_INF("SAADC buffer %d filled with sample %d ",current_value,i);
                
    /* STEP 7 - Retrieve the API-specific device structure and make sure that the device is ready to use  */





                average += current_value;
                if(current_value > max){
                    max = current_value;
                }
                if(current_value < min){
                    min = current_value;
                }
            }
            average = average/p_event->data.done.size;
            LOG_INF("SAADC buffer at 0x%x filled with %d samples", (uint32_t)p_event->data.done.p_buffer, p_event->data.done.size);
            LOG_INF("AVG=%d, MIN=%d, MAX=%d", (int16_t)average, min, max);
            counter=counter+0x0001;
            //you only need the write address and the eeprom address you want to read from 
     
        uint8_t sensor_regs[3] ={Eeprom_addr_write,0x00,0x00};
        //uint8_t temp_reading[2]= {0xFF,0x00};
        uint8_t temp_reading[4];
        ret = i2c_write_read_dt(&dev_i2c,&sensor_regs,3,&temp_reading,4);
        k_busy_wait(SLEEP_TIME_MS);
          for(int z=0; z < 5; z++){
        printk("waiting... %x\n\r");
       
          }

		if(ret != 0){
			printk("Failed to write/Read I2C device address %x at Reg. %x \n\r", dev_i2c.addr,sensor_regs[0]);
		}
		else{
		printk("memory content write&read %x\n\r",temp_reading[0]);
		printk("memory content write&read %x\n\r",temp_reading[1]);
		printk("memory content write&read %x\n\r",temp_reading[2]);
		printk("memory content write&read %x\n\r",temp_reading[3]);
		}

        
         nrfx_timer_disable(&timer_instance);
            break;

Related