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

STTS751 temperature sensor integration with nrf52

HI,

I am trying to use STTS751-1DP3F temp. sensor with nr52832. The drivers for sensors are given on:

https://github.com/STMicroelectronics/STMems_Standard_C_drivers/tree/master/stts751_STdC 

i tried to change the platform write and read function as follows

static int32_t platform_write(void *handle, uint8_t reg,
                              uint8_t *bufp,
                              uint16_t len)
{
		ret_code_t err_code;
    //HAL_I2C_Mem_Write(handle, STTS751_0xxxx_ADD_7K5, reg,
    //                  I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);
		m_xfer_done = false;
    err_code = nrf_drv_twi_tx(handle, reg, bufp, len, false);
    APP_ERROR_CHECK(err_code);
    while (m_xfer_done == false);
  return 0;
}
static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,
                             uint16_t len)
{
		ret_code_t err_code;
    //HAL_I2C_Mem_Read(handle, STTS751_0xxxx_ADD_7K5, reg,
     //                I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);
		m_xfer_done = false;
    err_code = nrf_drv_twi_rx(handle, reg, bufp, len);
    APP_ERROR_CHECK(err_code);
    
  return 0;
}

i also tried to redefine the structure as:

typedef struct {
  /** Component mandatory fields **/
  stmdev_write_ptr  write_reg;
  stmdev_read_ptr   read_reg;
  /** Customizable optional pointer **/
  //void *handle;
	nrf_drv_twi_t *handle;
} stmdev_ctx_t;

but  am getting following error

.\..\..\main.c(135): error: #513: a value of type "nrf_drv_twi_t" cannot be assigned to an entity of type "nrf_drv_twi_t *"
dev_ctx.handle = SENSOR_BUS;

please help me for the same

thanks and regards

Rajat

Parents
  • #include <stdio.h>
    #include "boards.h"
    #include "app_util_platform.h"
    #include "app_error.h"
    #include "nrf_drv_twi.h"
    #include "nrf_delay.h"
    
    
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    
    #include "stts751_reg.h"
    
    typedef union {
      int16_t i16bit;
      uint8_t u8bit[2];
    } axis1bit16_t;
    static axis1bit16_t data_raw_temperature;
    static float temperature_degC;
    static stts751_id_t whoamI;
    static uint8_t tx_buffer[1000];
    
    static int32_t platform_write(void *handle, uint8_t reg,
                                  uint8_t *bufp,
                                  uint16_t len);
    static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,
                                 uint16_t len);
    
    
    #define SENSOR_BUS  m_twi
    
    /* TWI instance ID. */
    #define TWI_INSTANCE_ID     0
    
    /* Indicates if operation on TWI has ended. */
    static volatile bool m_xfer_done = false;
    
    /* TWI instance. */
    static nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);
    
    /**
     * @brief Function for handling data from temperature sensor.
     *
     * @param[in] temp          Temperature in Celsius degrees read from sensor.
     */
    __STATIC_INLINE void data_handler(uint8_t temp)
    {
        NRF_LOG_INFO("Temperature: %d Celsius degrees.", temp);
    }
    
    /**
     * @brief TWI events handler.
     */
    void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context)
    {
        switch (p_event->type)
        {
            case NRF_DRV_TWI_EVT_DONE:
                if (p_event->xfer_desc.type == NRF_DRV_TWI_XFER_RX)
                {
                    //data_handler(m_sample);
                }
                m_xfer_done = true;
                break;
            default:
                break;
        }
    }
    
    /**
     * @brief UART initialization.
     */
    void twi_init (void)
    {
        ret_code_t err_code;
    
        const nrf_drv_twi_config_t twi_lm75b_config = {
           .scl                = ARDUINO_SCL_PIN,
           .sda                = ARDUINO_SDA_PIN,
           .frequency          = NRF_DRV_TWI_FREQ_100K,
           .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
           .clear_bus_init     = false
        };
    
        err_code = nrf_drv_twi_init(&m_twi, &twi_lm75b_config, twi_handler, NULL);
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_twi_enable(&m_twi);
    }
    
    
    static int32_t platform_write(void *handle, uint8_t reg,
                                  uint8_t *bufp,
                                  uint16_t len)
    {
    		ret_code_t err_code;
        //HAL_I2C_Mem_Write(handle, STTS751_0xxxx_ADD_7K5, reg,
        //                  I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);
    		m_xfer_done = false;
        err_code = nrf_drv_twi_tx(handle, reg, bufp, len, false);
        APP_ERROR_CHECK(err_code);
        while (m_xfer_done == false);
      return 0;
    }
    static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,
                                 uint16_t len)
    {
    		ret_code_t err_code;
        //HAL_I2C_Mem_Read(handle, STTS751_0xxxx_ADD_7K5, reg,
         //                I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);
    		m_xfer_done = false;
        err_code = nrf_drv_twi_rx(handle, reg, bufp, len);
        APP_ERROR_CHECK(err_code);
        
      return 0;
    }
    /**
     * @brief Function for reading data from temperature sensor.
     */
    
    /**
     * @brief Function for main application entry.
     */
    
    int main(void)
    {
        APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    	
    		stmdev_ctx_t dev_ctx;
    		dev_ctx.write_reg = platform_write;
    		dev_ctx.read_reg = platform_read;
    		dev_ctx.handle = SENSOR_BUS;
    	
    		stts751_device_id_get(&dev_ctx, &whoamI);
    	
        NRF_LOG_INFO("\r\nTWI sensor example started.");
        NRF_LOG_FLUSH();
        twi_init();
        //LM75B_set_mode();
    
        while (true)
        {
            nrf_delay_ms(500);
    				if ((whoamI.product_id != STTS751_ID_1xxxx) ||
           (whoamI.manufacturer_id != STTS751_ID_MAN) ||
           (whoamI.revision_id != STTS751_REV) ){
    			 NRF_LOG_INFO("\r\nTWI sensor working.");
    			 }
            NRF_LOG_FLUSH();
        }
    }
    
    /** @} */
    

  • there is nothing at line 135 in your main.c,  I do not see a correlation of that error to the code you provided

  • You need to change

    #define SENSOR_BUS m_twi

    to 

    #define SENSOR_BUS &m_twi

Reply Children
No Data
Related