<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>TWI reading and writing basics</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/84978/twi-reading-and-writing-basics</link><description>Hello all, 
 I have pinged the sensor on the &amp;quot;twi bus&amp;quot; successfully, now I am following the post on the read/write function that is needed to actually read the data off the sensor. This is what I am reading at the moment: https://medium.com/vicara-hardware</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 23 May 2022 09:02:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/84978/twi-reading-and-writing-basics" /><item><title>RE: TWI reading and writing basics</title><link>https://devzone.nordicsemi.com/thread/368947?ContentTypeID=1</link><pubDate>Mon, 23 May 2022 09:02:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eebc3713-0694-482f-8972-2499c56fe2e1</guid><dc:creator>MuRa</dc:creator><description>&lt;p&gt;What a simple &amp;quot;solution&amp;quot;! Just to let you know, that if I&amp;nbsp;have used the &amp;quot;no_stop&amp;quot; parameter as true , but only when calling the &amp;quot;reading&amp;quot; of the twi ! Indeed, on the write it does not applicable, so it is only used on &amp;quot;reading&amp;quot; ...&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI reading and writing basics</title><link>https://devzone.nordicsemi.com/thread/365964?ContentTypeID=1</link><pubDate>Tue, 03 May 2022 11:44:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a5537400-b545-4b41-816a-a6be9460143d</guid><dc:creator>MuRa</dc:creator><description>&lt;p&gt;Yes, and the &amp;nbsp;nrf_drv_twi_rx(), is this ok?&lt;/p&gt;
&lt;p&gt;Attaching the whole API for the sensor...&lt;/p&gt;
&lt;p&gt;Best.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;extern const nrf_drv_twi_t m_twi;
extern volatile bool m_xfer_done;

//nRF52DK specific I2C API call
#ifdef nRF52DK
	//All of the I2C API functions (For Example: HAL_I2C_Master_Transmit()) are being called from stm32f4xx_hal.h

	//hi2c1 - The variable to the I2C handler which is needed later in the Write and Read I2C function.
	//hi2c1 is defined in the stm32f4xx_hal.h and being called here via extern I2C_HandleTypeDef hi2c1;.
	//extern I2C_HandleTypeDef hi2c1;

	//Master sends I2C write command via pointer *Data from the Sensor API.
	//The function returns HAL_OK (=0) when there is no error and -1 when there is an error.
	int WriteI2C_Bus(struct TransferData *Data)
	{
		//Initialization of intial Error = 0
		ret_code_t Error = 0;

		//Define an array of 3 Bytes to be sent as I2C Write Command as shown in Fig. 10 in the Datasheet Page 7
		uint8_t WData[3]={Data-&amp;gt;RegisterAddress, Data-&amp;gt;WData[0], Data-&amp;gt;WData[1]};

		//Send I2C Write Command as shown in Fig. 10 in the Datasheet Page 7 with Error checking.
		/*Format defined by STM:
		*HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout).
		*HAL_I2C_Master_Transmit() is used for transmitting data to the I2C device. It takes following arguments:
		*
		*I2C_HandleTypeDef *hi2c - is the pointer to the i2c handler. hi2c1 is defined in the stm32f4xx_hal.h and being called here via extern I2C_HandleTypeDef *hi2c1;.
		*uint16_t DevAddress - is the Address of the I2C device (Need to be shifted by 1 to left since the input of function expects 8 bits).
		*uint8_t *pData  - is the pointer to the data to be transmitted.
		*uint16_t Size  - is the size of the transmitted data in bytes.
		*uint32_t Timeout - timeout in millisecond in case of any error.
		*Return Error.
		*/
		m_xfer_done = false;

		Error = nrf_drv_twi_tx(&amp;amp;m_twi, Data-&amp;gt;Slave_Address, WData, 3, false);  
                               
                APP_ERROR_CHECK(Error);
		while (m_xfer_done == false );
		//Error = HAL_I2C_Master_Transmit(&amp;amp;hi2c1, (Data-&amp;gt;Slave_Address)&amp;lt;&amp;lt;1, WData, 3, 100);

		//Return -1 when there is error and return NRF_SUCCESS (= 0) when no error
		if (Error != NRF_SUCCESS)
		{
			return -1;
		}
		else
		{
			return NRF_SUCCESS;
		}
	}

	//Master sends I2C Read command and save the read data via pointer *Data.
	//The function returns NRF_SUCCESS (=0) when no error and -1 when there is error.
	int ReadI2C_Bus (struct TransferData *Data)
	{
		//Initialization of intial Error = 0
		ret_code_t Error = 0;

		//Send I2C Read Command as shown in Fig. 10 in the Datasheet Page 7 with Error checking.
		/*Format defined by STM:
		*HAL_I2C_Mem_Read(I2C_HandleTypeDef *hi2c1, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout).
		*HAL_I2C_Mem_Read () is used for reading data from the I2C device. It has been used instead of HAL_I2C_Master_Receive() because it sends restart condition
		*while the latter which sends stop condition and thus not working. It takes following arguments:
		*
		*I2C_HandleTypeDef *hi2c - is the pointer to the i2c handler.
		*uint16_t DevAddress - is the Address of the I2C device (Need to be shifted by 1 to left since the input of function expects 8 bits).
		*uint16_t MemAddress - is the Internal memory address in the slave which is the register address.
		*uint16_t MemAddSize - the size of memory address (in Byte) which is the size of register address (In the case of Vishay&amp;#39;s Sensor always 1 Byte).
		*uint8_t *pData  - is the pointer to the data to be received.
		*uint16_t Size  - is the size of the received data in bytes.
		*uint32_t Timeout - timeout in millisecond in case of any error.
		*Return Error.
		*
		*/
		m_xfer_done = false;
		Error = nrf_drv_twi_tx(&amp;amp;m_twi, Data-&amp;gt;Slave_Address, &amp;amp;Data-&amp;gt;RegisterAddress, 1, false);
		APP_ERROR_CHECK(Error);
	
		while (m_xfer_done == false );
	
		m_xfer_done = false;
		
		/* Read from register */
		Error = nrf_drv_twi_rx(&amp;amp;m_twi, Data-&amp;gt;Slave_Address, Data-&amp;gt;RData, 2);
		APP_ERROR_CHECK(Error);
	
		while (m_xfer_done == false );
		
		//Error = HAL_I2C_Mem_Read(&amp;amp;hi2c1, (Data-&amp;gt;Slave_Address)&amp;lt;&amp;lt;1, Data-&amp;gt;RegisterAddress, 1,Data-&amp;gt;RData,2,100);

		//Return -1 when there is error and return NRF_SUCCESS (= 0) when no error
		if (Error !=NRF_SUCCESS)
		{
			return -1;
		}
		else
		{
			return NRF_SUCCESS;
		}
	}

	//Master sends I2C Gesture Read command and save the read data via pointer *Data.
	//The function returns NRF_SUCCESS (=0) when no error and -1 when there is error.
    int ReadI2C_Bus_Gesture_Mode(struct GestureTransferData *Data)
	{
		//Initialization of intial Error = 0
		ret_code_t Error = 0;

		//Send I2C Gesture Read Command as shown in the Application Note Page 19 with Error checking.
		/*Format defined by STM:
		*HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout).
		*HAL_I2C_Master_Receive () is used for reading data from the I2C device. It has been used instead of HAL_I2C_Mem_Read() because no restart condition is *needed.
		*It takes following arguments:
		*
		*I2C_HandleTypeDef *hi2c - is the pointer to the i2c handler. hi2c1 is defined in the stm32f4xx_hal.h and being called here via extern I2C_HandleTypeDef *hi2c1;.
		*uint16_t DevAddress - is the Address of the I2C device (Need to be shifted by 1 to left since the input of function expects 8 bits).
		*uint8_t *pData  - is the pointer to the data to be received.
		*uint16_t Size  - is the size of the received data in bytes (For Gesture Stream 6 Bytes are needed).
		*uint32_t Timeout - timeout in millisecond in case of any error.
		*Return Error.
		*
		*/
		/*m_xfer_done = false;
		err_code = nrf_drv_twi_tx(&amp;amp;m_twi, Data-&amp;gt;Slave_Address, &amp;amp;Data-&amp;gt;RegisterAddress, 1, false);
		APP_ERROR_CHECK(err_code);
	
		while (m_xfer_done == false );*/
	
		m_xfer_done = false;
		
		/* Read from register */
		Error = nrf_drv_twi_rx(&amp;amp;m_twi, Data-&amp;gt;Slave_Address, Data-&amp;gt;RData, 6);
		APP_ERROR_CHECK(Error);
	
		while (m_xfer_done == false );
		
		//Error = HAL_I2C_Master_Receive(&amp;amp;hi2c1,(Data-&amp;gt;Slave_Address)&amp;lt;&amp;lt;1,Data-&amp;gt;RData,6,100);

		//Return -1 when there is error and return NRF_SUCCESS (= 0) when no error
		if (Error != NRF_SUCCESS)
		{
			return -1;
		}
		else
		{
			return NRF_SUCCESS;
		}
	}
#endif&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI reading and writing basics</title><link>https://devzone.nordicsemi.com/thread/364737?ContentTypeID=1</link><pubDate>Mon, 25 Apr 2022 13:17:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b8c05b84-ff72-419b-8711-ca8b023caf92</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Are you calling&amp;nbsp;nrf_drv_twi_tx() in your application?&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI reading and writing basics</title><link>https://devzone.nordicsemi.com/thread/364700?ContentTypeID=1</link><pubDate>Mon, 25 Apr 2022 11:52:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c3453d95-1bdc-41f7-ba31-5de2e8e305da</guid><dc:creator>MuRa</dc:creator><description>&lt;p&gt;Hello Kenneth thank you for your reply, sorry for being such a beginner, but&amp;nbsp;I had a look and so far I am seeing this code within the &amp;quot;nrf_drw_twi.h&amp;quot;&amp;nbsp; when debugged :&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;__STATIC_INLINE
ret_code_t nrf_drv_twi_tx(nrf_drv_twi_t const * p_instance,
                          uint8_t               address,
                          uint8_t const *       p_data,
                          uint8_t               length,
                          bool                  no_stop)
{
    ret_code_t result = 0;
    if (NRF_DRV_TWI_USE_TWIM)
    {
        result = nrfx_twim_tx(&amp;amp;p_instance-&amp;gt;u.twim,
                                address, p_data, length, no_stop);
    }
    else if (NRF_DRV_TWI_USE_TWI)
    {
        result = nrfx_twi_tx(&amp;amp;p_instance-&amp;gt;u.twi,
                               address, p_data, length, no_stop);
    }
    return result;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Indeed, it seems that &amp;quot; no_stop &amp;quot; is used , so, do I have to change this, and into what?&amp;nbsp;Not really sure how to implement what is expected from the above instruction of the Read I2C protocol ...&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Any help is much appreciated!&lt;/p&gt;
&lt;p&gt;Best.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;PS this is my twi_init()&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void twi_init(void) {
  ret_code_t err_code;

  const nrf_drv_twi_config_t twi_config = {
      .scl = 26, // Add you SCL Pin Here
      .sda = 27, // Add you SDA Pin Here
      .frequency = NRF_DRV_TWI_FREQ_100K,
      .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
      .clear_bus_init = false};

  err_code = nrf_drv_twi_init(&amp;amp;m_twi, &amp;amp;twi_config, twi_handler, NULL);
  APP_ERROR_CHECK(err_code);

  nrf_drv_twi_enable(&amp;amp;m_twi);
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI reading and writing basics</title><link>https://devzone.nordicsemi.com/thread/364600?ContentTypeID=1</link><pubDate>Mon, 25 Apr 2022 07:17:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:00df344c-096d-4487-9dfb-16fd7f34f902</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;If you are referring to my answer here:&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/84978/twi-reading-and-writing-basics/363652#363652"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/84978/twi-reading-and-writing-basics/363652#363652&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Then that is already available in the twi driver, it&amp;#39;s just calling the twi api with the no_stop bit set or cleared according to your expecations. I suggest to have a logic analyzer at hand so you can see the transacations on byte level, with the start, stop and re-start conditions.&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI reading and writing basics</title><link>https://devzone.nordicsemi.com/thread/364159?ContentTypeID=1</link><pubDate>Thu, 21 Apr 2022 09:27:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:630f10a7-a468-43b5-8930-8c9a054ca802</guid><dc:creator>MuRa</dc:creator><description>&lt;p&gt;Hello Kenneth!&lt;/p&gt;
&lt;p&gt;Thank you for your reply, information,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;would you please be so kind and let me know,&lt;/p&gt;
&lt;p&gt;do I have to implement the function you are referring or it can be found in the existing drivers?&lt;/p&gt;
&lt;p&gt;In that case where, where it has to be implemented or where it can be found?&lt;/p&gt;
&lt;p&gt;Thank you in advance for your answer.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;best.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI reading and writing basics</title><link>https://devzone.nordicsemi.com/thread/363652?ContentTypeID=1</link><pubDate>Tue, 19 Apr 2022 14:09:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32a76c41-9d4b-42be-b89f-375d63949de2</guid><dc:creator>Kenneth</dc:creator><description>[quote user="mu234"]For the Read I2C protocol, it is important that the restart condition is being sent before the second slave address and please ensure that no Stop condition being sent before the restart condition because some I2C library sends stop condition before restart condition ???[/quote]
&lt;p&gt;This is typically handled by the no_stop parameter, e.g.:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**
 * @brief Function for sending data to a TWI slave.
 *
 * The transmission will be stopped when an error occurs. If a transfer is ongoing,
 * the function returns the error code @ref NRF_ERROR_BUSY.
 *
 * @param[in] p_instance Pointer to the driver instance structure.
 * @param[in] address    Address of a specific slave device (only 7 LSB).
 * @param[in] p_data     Pointer to a transmit buffer.
 * @param[in] length     Number of bytes to send.
 * @param[in] no_stop    If set, the stop condition is not generated on the bus
 *                       after the transfer has completed successfully (allowing
 *                       for a repeated start in the next transfer).
 *
 * @retval NRF_SUCCESS                  If the procedure was successful.
 * @retval NRF_ERROR_BUSY               If the driver is not ready for a new transfer.
 * @retval NRF_ERROR_INTERNAL           If an error was detected by hardware.
 * @retval NRF_ERROR_INVALID_ADDR       If the EasyDMA is used and memory adress in not in RAM.
 * @retval NRF_ERROR_DRV_TWI_ERR_ANACK  If NACK received after sending the address in polling mode.
 * @retval NRF_ERROR_DRV_TWI_ERR_DNACK  If NACK received after sending a data byte in polling mode.
 */
__STATIC_INLINE
ret_code_t nrf_drv_twi_tx(nrf_drv_twi_t const * p_instance,
                          uint8_t               address,
                          uint8_t const *       p_data,
                          uint8_t               length,
                          bool                  no_stop);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI reading and writing basics</title><link>https://devzone.nordicsemi.com/thread/363146?ContentTypeID=1</link><pubDate>Wed, 13 Apr 2022 09:48:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4850ecce-c666-4e37-971f-2a9583f277b5</guid><dc:creator>MuRa</dc:creator><description>&lt;p&gt;Thank you and I am looking forward to the reply.&lt;/p&gt;
&lt;p&gt;Indeed, happy Easter holidays!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI reading and writing basics</title><link>https://devzone.nordicsemi.com/thread/363110?ContentTypeID=1</link><pubDate>Wed, 13 Apr 2022 07:17:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:11cb76f6-1000-49c1-abb9-acdc9e0b57c8</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Our experts on this are out of office due to the Easter Holiday.&lt;/p&gt;
&lt;p&gt;We will have a closer look at this case during next week.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI reading and writing basics</title><link>https://devzone.nordicsemi.com/thread/362324?ContentTypeID=1</link><pubDate>Thu, 07 Apr 2022 11:48:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:57bcc288-c141-471f-b570-a4a3183f0b87</guid><dc:creator>MuRa</dc:creator><description>&lt;p&gt;Hello All&lt;/p&gt;
&lt;p&gt;the library was compiled and the&amp;nbsp;TWI is added, the sensor is connected to the nrf52dk and pullups are across the SCK, SDA ... However, I am getting strange behavior.&lt;/p&gt;
&lt;p&gt;In&amp;nbsp; general, the sensor readings freeze at some point, interestingly only when the barrier is introduced not at all channels, one is not affected, actually it looks like the first &amp;quot;goes&amp;quot; to the second, and eventually first and third freeze, while the second works normally :) all the way. The reset is pressed to start from the beginning...&lt;/p&gt;
&lt;p&gt;Please have a look at the picture (JScope) and please comment whether the nRF TWI driver&amp;nbsp;fulfils&amp;nbsp;the following write and read I2C protocols. &lt;strong&gt;For the Read I2C protocol, it is important that the restart condition is being sent before the second slave address and please ensure that no Stop condition being sent before the restart condition because some I2C library sends stop condition before restart condition ???&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Best.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/gesture_5F00_mode.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI reading and writing basics</title><link>https://devzone.nordicsemi.com/thread/354503?ContentTypeID=1</link><pubDate>Wed, 23 Feb 2022 09:44:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc6012b0-a848-48b2-80ac-922a3f615656</guid><dc:creator>MuRa</dc:creator><description>&lt;p&gt;Hi Ahmed&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;thank your for your input, of course, here is the datasheet&amp;nbsp;&lt;a href="https://www.vishay.com/docs/84251/vcnl4035x01.pdf"&gt;vcnl4035x01.pdf (vishay.com)&lt;/a&gt;&amp;nbsp;and I have the sensor on this address #define VCNL4035_ADDR 0x60 I have as well attached the init that I am using :&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**
 * @brief UART initialization.
 */
void twi_init (void)
{
    ret_code_t err_code;

    const nrf_drv_twi_config_t twi_vcnl4035_config = {
       .scl                = 27,
       .sda                = 26,
       .frequency          = NRF_DRV_TWI_FREQ_400K,
       .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
       .clear_bus_init     = false
    };

    err_code = nrf_drv_twi_init(&amp;amp;m_twi, &amp;amp;twi_vcnl4035_config, twi_handler, NULL);
    APP_ERROR_CHECK(err_code);

    nrf_drv_twi_enable(&amp;amp;m_twi);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Here is the TWI handler , I guess this is the call back function ?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**
 * @brief TWI events handler.
 */
void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context)
{
    switch (p_event-&amp;gt;type)
    {
        case NRF_DRV_TWI_EVT_DONE:
            if (p_event-&amp;gt;xfer_desc.type == NRF_DRV_TWI_XFER_RX)
            {
                data_handler(m_sample);
            }
            m_xfer_done = true;
            break;
        default:
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Anyway, here is the library to make things easier&amp;nbsp;&lt;a href="https://www.vishay.com/ppg?84251&amp;amp;designtools-ppg"&gt;VCNL4035X01 Fully Integrated Proximity and Ambient Light Sensor With I&amp;sup2;C Interface and Interrupt Function for Gesture Applications | Vishay&lt;/a&gt;&amp;nbsp;I have downloaded the code, trying to use it!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI reading and writing basics</title><link>https://devzone.nordicsemi.com/thread/354465?ContentTypeID=1</link><pubDate>Wed, 23 Feb 2022 07:22:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6bb9dada-05a8-4b66-9015-c60f1ca986eb</guid><dc:creator>ahmad@mikrostartech.com</dc:creator><description>&lt;p&gt;Hi ,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The macros defined in the code needs to be according to your sensor . This code is written for the LM75 (a digital temperature sensor&amp;nbsp;with i2c/twi interface) . If you can share datasheet or part number of your sensor may be I can help.&lt;/p&gt;
&lt;p&gt;All the examples given in the SDK use a relative part to the sdk directories so one way is to clone the whole sdk (obviously removing all the other examples) and compile or just clone the certain example in the examples directory in the same directory so the relative path is not disturbed .&lt;/p&gt;
&lt;p&gt;Regards ,&lt;/p&gt;
&lt;p&gt;Ahmed&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI reading and writing basics</title><link>https://devzone.nordicsemi.com/thread/354127?ContentTypeID=1</link><pubDate>Mon, 21 Feb 2022 12:19:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c0e52147-42df-4271-8105-69ca874a6f4d</guid><dc:creator>MuRa</dc:creator><description>&lt;p&gt;Hi and thank you for your input, it really helps. Indeed, this example should be a good start and I will have a go, however, can this example as well be use to use the library , how, or is this just to use for predefined registers?&amp;nbsp;Such as these:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;#define LM75B_REG_TEMP 0x00U&lt;br /&gt;#define LM75B_REG_CONF 0x01U&lt;br /&gt;#define LM75B_REG_THYST 0x02U&lt;br /&gt;#define LM75B_REG_TOS 0x03U&lt;/p&gt;
&lt;p&gt;For example, the library defines all the registers including the values and methods, etc. So, it is of importance to use the library... However, you mentioned I can use the &amp;quot;&lt;span&gt;twi_write and&amp;nbsp;twi_read function&amp;quot; as posted above , can you be more specific, maybe an example of how to actually do this&amp;nbsp;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you in advance.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;PS while cloning the &amp;quot;project&amp;quot; I got an error when compiling, namely &amp;quot;C:/components/libraries/log/src/nrf_log_backend_rtt.c does not exist.&amp;quot; do I have to clone it together with the whole directory path?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI reading and writing basics</title><link>https://devzone.nordicsemi.com/thread/354115?ContentTypeID=1</link><pubDate>Mon, 21 Feb 2022 11:47:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:41bb2e5c-0a9d-4fad-843a-e9ea2c20e64a</guid><dc:creator>ahmad@mikrostartech.com</dc:creator><description>&lt;p&gt;Hello MuRa ,&lt;/p&gt;
&lt;p&gt;I am assuming you are starting a new project if that is the case you can clone the example twi_sensor shipped with the nrf52 sdk (your sdk52 \examples\peripheral). You&amp;#39;ll find twi initialization &lt;span&gt;twi_init() in which you need to set your sda and scl pin accordingly to your sensor and soc pins or you can use the default twi pins for you devkit. From there you can use your&amp;nbsp;twi_write and&amp;nbsp;twi_read function you just mentioned in your question. I hope it helped.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>