Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BMA425 issue in I2C fast mode (400kbps)

    BMA425 issue in I2C fast mode (400kbps)

    alexzhangyc
    Member

    Hi expert, recently i am working on our BLE application platform with BMA425 on broad for motion tracking. At the first i configed MCU I2C as standard mode (100kbps) to connect BMA425 and you know 425 is set as header and powersave mode with FIFO enabled (No irq and watermark used). MCU app will read FIFO data when each time my timer handler is serviced per 10 seconds (BMA425 ODR is 6.25Hz).

    So my logic is when timer handler is running, i disable powersave mode firstly plus a minor delay (1ms), after that i issue the brust read of FIFO data. When 10S FIFO data is ate up, i enable the powersave mode again.  The code is working fine under I2C standard mode. So I change the I2C as fast mode (a.k.a. 400Kbps), the issue is coming then, you know, i still can read FIFO data but I find more time is consumed for completion of FIFO read comparing with standard mode. Typically 50ms in standard mode but 125ms in fast mode. That's weird ryt?  Fast mode I2C will consume FIFO date faster than the standard. Could you give me some clues about this issue? Thanks.

    6 REPLIES 6

    Vincent
    Community Moderator
    Community Moderator

    Please share your part of source code for sensor initialize and also the FIFO read out part with also the logic analyzer plotter on bus for 100K and 400KHz. 

    Thanks for the reply. Here is my code snippet:

    the init code logic about BMA425

    void bma425_init(void)
    {
                  struct bma4_accel_config accel_conf;
    
    		/* Modify the accel handle parameters */
    		accel.dev_addr = BMA4_I2C_ADDR_PRIMARY;
    		accel.interface = BMA4_I2C_INTERFACE;
    		accel.bus_read = i2c_read_register;
    		accel.bus_write = i2c_write_register;
    		accel.delay = delay_x_ms;
    		accel.read_write_len = 8;
    		
    	        /* Assign the desired settings for fifo */
    		fifo_frame.data = fifo_buff;
    		fifo_frame.length = BMA_MAX_BRUST_RD;
    		accel.fifo = &fifo_frame;
    	
    	       /* Set up BMA425 device address */
    	       i2c_set_dev_addr(BMA4_I2C_ADDR_PRIMARY);
    
    		/* Initialize the instance */
    		rslt |= bma423_init(&accel);
    		
    		/* Enable the accelerometer */
    		rslt |= bma4_set_accel_enable(BMA4_MANUAL_ENABLE, &accel);
    
    		/* Assign the desired settings */
    		accel_conf.odr = BMA4_OUTPUT_DATA_RATE_6_25HZ;                
    		accel_conf.range = BMA4_ACCEL_RANGE_2G;
    		accel_conf.bandwidth = BMA4_ACCEL_OSR4_AVG1;
    		accel_conf.perf_mode = BMA4_CIC_AVG_MODE;
    		
    		/* Set the configuration */
    		rslt |= bma4_set_accel_config(&accel_conf, &accel);
    		delay_x_ms(1);
    
    		/* Disable the advanced power save mode to configure the FIFO buffer */
    		rslt |= bma4_set_advance_power_save(BMA4_ENABLE, &accel);
    		
    		/* Configure the FIFO buffer */	
    		rslt |= bma4_set_fifo_config((BMA4_FIFO_ACCEL|BMA4_FIFO_HEADER), BMA4_ENABLE, &accel);
    
    		if (rslt != BMA4_OK) {
    		    MY_DBG("BMA425 init failed.\n\r");
    		} else {
    		    MY_DBG("BMA425 init OK.\n\r");
    		}
    }

    In timer handler service we issue the FIFO read out:

    #define FRAME_SIZE (7)  /*< in header mode: 1B header + 6B accel */
    #define FIFO_WATERMARK_DEPTH ((ACCEL_HZ * FRAME_SIZE+1))
    
    void handle_bma425_accel_fifo(void)
    {
    	  uint16_t n_instances;
    	  int16_t n_expected;
    	  uint16_t fifo_len;
    
    	  bma4_set_advance_power_save(BMA4_DISABLE, &accel);
    
    	  bma4_get_fifo_length(&fifo_len, &accel);
    	  MY_DBG("FIFO len %d.\n\r", fifo_len);
    	
    	  if (fifo_len < FIFO_WATERMARK_DEPTH) {
    			  MY_DBG("Read FIFO too fast [%d].\n\r", fifo_len);
    			  return;
    	  }
    	  
              /* Consume 10 seconds accel data in Fifo */
    	  n_expected =62;
    	  do {
    			  n_instances = n_expected;
    			
    				/* Read data from the sensor FIFO buffer */
    				bma4_read_fifo_data(&accel); 
    				bma4_extract_accel(&sens_data[62 - n_expected], &n_instances, &accel); 		  
    				n_expected -= n_instances;
    	  } while (n_expected > 0);
    	       
    	  if(n_expected==0) {			
    		  bma4_set_advance_power_save(BMA4_ENABLE, &accel); 
    		  // handle ACC data	
    	  }			
    }

     

    when set as 400K, I2C bus timing is here:

    i2c.png

    in standard mode, we see 10s fifo data handle is ~ 50ms

    dui.png

    but we set as fast mode, 120ms is observed.

    BR,

    Alex

     

    Vincent
    Community Moderator
    Community Moderator

    Let's shink down the problem first to see if the time difference is coming from bus read or somewhere else. 

    First we focus on following funciton execute time: 

    bma4_read_fifo_data(&accel);

     

    Before you call this, please adding the following setence:

    dev->fifo->length =  fifo_lengh;

    this fifo_length is get from previous API "bma4_get_fifo_length".  please also print this fifo_length out for debug. 

    Hi,expert

    Thanks for your reply !

    The following picture is the log of fifo length in the case of abnormal power consumption.

    We can be sure that the power consumption is getting longer not because of more data, but because of the problem of reading fifo(It shows a trend of decreasing length).

    Is there a problem with my other configuration?

    We are also doing some other related tests to look for problems and continue to wait for your Suggestions.

    B/R

     

    Oscilloscope waveform.pngfifo_length.png

     

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist