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

Serial display of data using TWI

Hi all, 

i am using twi_scanner and twi_sensor as  templates to get data from CCS811 Air Quality sensor with PCA10040 and SDK 15.3.
But i cannot get the data printed in putty for example. 

I believe the issue could be on my set_mode() function, in which i try to set measurements every one second and instantiate the data register.
But putty is not showing anything.

Here is my set_mode function.

/**
 * @brief Function for setting constant mode 
 * Measurements every second
 */
void set_mode(void) 
{
    ret_code_t err_code;
	
	//Setting values of specific bits of the register byte
    /* Writing to CCS811_REG_CONF "1" set sensor in NORMAL mode. */
	
    uint8_t reg[2] = {CCS811_REG_MEAS_MODE, 1U };
    err_code = nrf_drv_twi_tx(&m_twi, device_id, reg, sizeof(reg), false);
    APP_ERROR_CHECK(err_code);
    while (m_xfer_done == false);
	
	NRF_LOG_INFO(" ************************************ ");
	NRF_LOG_INFO("Setting data pointer.");
	
	 /* Writing to pointer byte. */
	reg[0] = CCS811_REG_ALG_RESULT_DATA ;
    m_xfer_done = false;
    err_code = nrf_drv_twi_tx(&m_twi, device_id, reg, 1, false);
    APP_ERROR_CHECK(err_code);
    while (m_xfer_done == false);
}

Thanks,

Parents Reply Children
  • Hi Jared, thanks for reply.

    Yes, I am using the recommended settings.
    NRF LOG outputs are visible on putty, but not the data.

    TWI handle is called, but then nothing is shown on putty.

    <Note about the sensor>
    I need to set measurement mode on the chip, which i do in the set_mode() function by setting CCS811_REG_MEAS_MODE register to 1, this will set the sensor to measure values every second. 
    <...>


    Anyway, I removed the lines 17 to 25 from the function set_mode(), and created a new function called read_data_sensor(), which prints the strange value of 253 on putty.  You can see the  code for read_data_sensor()  bellow

    static void read_sensor_data()
    {
        ret_code_t err_code;
    	m_xfer_done = false;
    	
    	//Setting sensor reading register 
        uint8_t reg = CCS811_REG_RAW_DATA;
    	
        err_code = nrf_drv_twi_tx(&m_twi, DEVICE_ID, &reg, sizeof(reg), false);
        APP_ERROR_CHECK(err_code);
    	if (err_code == NRF_SUCCESS){ //	If the procedure was successful.
    			NRF_LOG_INFO("TX OK");
    		} 
    
     
        err_code = nrf_drv_twi_rx(&m_twi, DEVICE_ID, &sample_data, sizeof(sample_data));
    	APP_ERROR_CHECK(err_code);
    	nrf_delay_ms(200);
    	
    			
            if (err_code == NRF_SUCCESS){ //	If the procedure was successful.
    			NRF_LOG_INFO("Data received - reading data()");
    	        
    	    } 
    		
    }
    



    And well i am stuck here, just getting 253 on putty, as if the register is ignored somehow =\
     

  • Where do you print "sample_data", and when is read_data_sensor() called? Have you checked that the NRF_DRV_TWI_EVT_DONE event has been generated before you read? If yes, then I suggest using the debugger to check what is stored in sample_data after a rx operation.

Related