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;

  • Hi there,

    Exactly which function is returning the error and what error is returned?

    Have you been able to successfully write to the external memory before? 

    regards

    Jared 

  • Yes, i manage to succesfully write and read to the external eeprom program that only does that, but now i want to write the buffer from the ADC example using the DPPI to the eeprom but am having errors and its not working

    first let me show u the little program i made to make it work to write and read from the eeprom:

    uint8_t config[7] = {Eeprom_addr_write,0x00,0x00,0x00,0x01,0x02,0x03};
    
    	ret = i2c_write_dt(&dev_i2c, config, sizeof(config));
    		k_msleep(SLEEP_TIME_MS);
    	if(ret != 0){
    		printk("Failed to Write to I2C device address %x at Reg. %x \n", dev_i2c.addr,config[0]);
    		return -1;
    	}
    
    
    uint8_t data;
    ret = i2c_read_dt(&dev_i2c, &data, sizeof(data));
    k_msleep(SLEEP_TIME_MS);
    		if(ret != 0){
    			printk("Failed to read from I2C device address %x at Reg. %x \n\r", dev_i2c.addr,config[0]);
    		}
    		else{
    		printk("memory content first read %x\n\r",data);
    		}
    //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_msleep(SLEEP_TIME_MS);
    		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]);
    		}
    	while (1) {
    /* STEP 10 - Read the temperature from the sensor */
    
    /*conversion to MV may nto be supported*/
    
    /* STEP 11 - Convert the two bytes to a 12-bits */
    
    		//k_msleep(SLEEP_TIME_MS);
    	
    }
    }
    

    and i get succesfully the readings on the terminal as follow:

  • But when  i integrate writing to the Eeprom in the Adc using dppi example i get the following error:

  • but as you can see am using the zephyr i2c library for this. do i need to use the nrfx library in this case? is there any sample for this?

  • I will continue to help with this ticket.

    I think that you should be able to use zephyr i2c for this.

    A classic error is to try to use the i2c send function directly from the ADC callback.
    Do you do this?

    Looks like you get an error here. Can you verify that?

    Try to increase CONFIG_I2C_NRFX_TRANSFER_TIMEOUT?

    Regards,
    Sigurd Hellesvik

Related