This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

TWI and BLE on nRF52840 DK

Hello, 

I am interfacing nRF52840 DK with the MAX30101 sensor. I am able to execute all the TWI transactions necessary by using port 0 pin 27 as SCL and port 0 pin 26 as SDA. 

However when i use port 0 pin 14 as SCL and port 0 pin 13 as SDA I am not getting any output. I used ble_app_uart example and added TWI drivers. Are pins 14 and 13 assigned to something else in the ble_app_uart example? 

Changing pins is not an option, please tell me how I can go about working TWI on these pins. 

Thank you. 

  • You should be able to do that if you don't initialize the buttons and lEDs. Remove buttons_leds_init(&erase_bonds) from main.

  • Hi Gautham,

    I am working on similar boards, I have configured the sensor correctly but when I read FIFO I get zero. Can you help me out with configurations?

  • Hi Muhammad, 
    Sure, i can help you. can you tell me your configuration values?

  • /**@brief Function for initializations of max30101 .
     *
     * @param[in] p_instance  TWI instance.
    */
    void setup(nrf_drv_twi_t const * p_instance)
    {
    	 
    		//Setting the Mode configuration register
    		regwrite8(p_instance,MAX30101_MODECONFIG, MAX30101_MODE_MULTILED); // Setting the mode to Multi LED i-e 0x07
    
    	   // Multi Led mode control configuration register setup for slotx
        regwrite8(p_instance,MAX30101_MULTILEDCONFIG1,MULTI_LED_1); // Register 0x11 setup to value 0x21
    	
    		regwrite8(p_instance,MAX30101_MULTILEDCONFIG2,MULTI_LED_3); // Register 0x12 setup to value 0x03
    	
    		//LED Pulse applitude register to set the current in the led	
    		regwrite8(p_instance,MAX30101_LED1_PULSEAMP,powerLevel); // Current register setup to value 0x1F
    		regwrite8(p_instance,MAX30101_LED2_PULSEAMP,powerLevel);
    		regwrite8(p_instance,MAX30101_LED3_PULSEAMP,powerLevel);
    
    
      
     // Configuration register setting
    	/*
    	*	Fifo roll over enabled
    	*	Fifo sample average to 4
    	*	Generate Interrupt when 29 samples are filled in memeory
    	*/
    		regwrite8(p_instance,MAX30101_FIFOCONFIG,MAX30101_CONF_FIFO);// Fifo configuration register setup
    	
    		// Spo2 Configuration setup 
    		/*
    		*	ADC range set to 4096
    		* Sample Rate 400
    		*	LED pulse width 411
    		*/
    		regwrite8(p_instance,MAX30101_PARTICLECONFIG,0x2F);
    		// Clear fifo
    		clearFIFO(p_instance);
    	
    }
    
    /**@brief Function for writing the data to max30101 .
     *
     * @param[in] p_instance  TWI instance.
     * @param[in] RegAddr     Register Address to be written.
     * @param[in] data        Data to be written to the register.
     */
    void regwrite8(nrf_drv_twi_t const * p_instance, uint8_t RegAddr, uint8_t data)
    {
    	uint8_t reg[2] = {RegAddr, data};
    	nrf_drv_twi_tx(p_instance, MAX30101_ADDRESS, reg, sizeof(reg), false); //Repeated start is disabled
    	nrf_delay_ms(5);
    }
    

    Code to Initialize the sensor

  • Functions that I have used to get data from FIFO are following

    /**@brief Function for reading the MAX30101_FIFOREADPTR register .
     *
     * @param[in] p_instance  TWI instance.
    */
    uint8_t getRDptr(nrf_drv_twi_t const * p_instance)
    {
    	uint8_t data;
    	regread8(p_instance,MAX30101_FIFOREADPTR,&data,true);
    	return data;
    }
    
    /**@brief Function for reading the MAX30101_FIFOWRITEPTR register .
     *
     * @param[in] p_instance  TWI instance.
    */
    uint8_t getWRptr(nrf_drv_twi_t const * p_instance)
    {
    	uint8_t data;
    	regread8(p_instance,MAX30101_FIFOWRITEPTR,&data,true);
    	return data;
    }
    
    /**@brief Function for reading the data from FIFO buffer .
     *
     * @param[in] p_instance  TWI instance.
    */
    uint8_t *getdata(nrf_drv_twi_t const * p_instance)
    {
    	uint8_t wrptr=0;
    	uint8_t rdptr=0;
    	uint8_t scount=0; //Number of samples to be read from the sensor
    	static uint8_t data[3];
    	wrptr= getWRptr(p_instance); // FIFO_WR pointer 
    	rdptr= getRDptr(p_instance); // FIFO_RD pointer
    	scount =wrptr-rdptr;
    	if(scount<0)scount+=32;
    	nrf_drv_twi_tx(p_instance, MAX30101_ADDRESS, &MAX30101_FIFODATA, sizeof(MAX30101_FIFODATA), true);
    	nrf_delay_ms(1);
    	for(int i=0; i<scount;i++)
    	{
    		nrf_drv_twi_rx(p_instance, MAX30101_ADDRESS, &data[2], 1/*Read only 1 byte*/);
    		nrf_delay_ms(1);
    		nrf_drv_twi_rx(p_instance, MAX30101_ADDRESS, &data[1], 1);
    		nrf_delay_ms(1);
    		nrf_drv_twi_rx(p_instance, MAX30101_ADDRESS, &data[0], 1);
    		nrf_delay_ms(1);
    	}
    	
    	return data;
    }
    

Related