<?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 with SDK v14.2.0 and IQS231A</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/35887/twi-with-sdk-v14-2-0-and-iqs231a</link><description>Dear Nordic Team, 
 
 We are using nRF52832 with a IQS231A for proximity detection for a new product, the pins are connected to SDA and SCL and everything is routed as in datasheet. however, I got to know today this sensor can only enter I2C mode in </description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 28 Jun 2018 09:25:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/35887/twi-with-sdk-v14-2-0-and-iqs231a" /><item><title>RE: TWI with SDK v14.2.0 and IQS231A</title><link>https://devzone.nordicsemi.com/thread/138053?ContentTypeID=1</link><pubDate>Thu, 28 Jun 2018 09:25:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9fa615dc-8f06-45b9-97f9-0d2c551600bc</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;I assume the correct procedure would be to:&lt;/p&gt;
&lt;p&gt;1. uninit or twi driver not initialized&lt;br /&gt;2. control power to the sensor and&amp;nbsp;pull up&amp;#39;s for the sda/scl&lt;br /&gt;4. small delay for power to stabilize&lt;br /&gt;5.&amp;nbsp;init twi driver&lt;br /&gt;6. execute twi transfer&lt;br /&gt;7. no luck? then remove power to the sensor and pull up&amp;#39;s for sda/scl, and&amp;nbsp;repeat from 1&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI with SDK v14.2.0 and IQS231A</title><link>https://devzone.nordicsemi.com/thread/138043?ContentTypeID=1</link><pubDate>Thu, 28 Jun 2018 06:18:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0000c3ae-6c9f-42be-97b2-b55e02bf039a</guid><dc:creator>Moe</dc:creator><description>&lt;p&gt;Hi Kenneth,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So I followed exactly the example in the thread that you mentioned &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/11032/i2c-how-do-i-specify-a-register-address-to-read-from-when-calling-nrf_drv_twi_rx"&gt;here&lt;/a&gt;, but unfortunately i was not able to have an I2C/ TWI signal in my logic analyzer, I was able to have some sort of a signal, My new code goes like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;app_util_platform.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;nrf_drv_twi.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;
#include &amp;quot;nrf_drv_gpiote.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;

/**********************new includes****************************************/

/* TWI instance ID. */
#define TWI_INSTANCE_ID     0


/******************************IQS231A at test mode**********************************************/
#define IQS231A_I2C_ADDR_TEST_MODE        (0x45U &amp;gt;&amp;gt; 1) //entering test mode aka I2C mode

#define REGISTER_ADDR_CONFIRM_TEST_MODE 0x0F
																										
/********************************OTP test mode RAM addresses*******************************************************/
#define OTP_BANK_0			0x10U  
#define OTP__BANK_1 			0x11U 
#define OTP_BANK_2			0x12U
#define OTP_BANK_3			0x13U
/*********************************Memory map I2C reg*********************************************/

#define PRODUCT_NUMBER 			0x00U
#define SOFTWARE_VERSION		0x01U
#define	DEBUG_EVENTS			0x02U
#define COMMANDS			0x04U
#define QUICK_RELEASE			0x08U
#define MOVEMENT			0x09U
#define PROX_THRESHOLDS			0x0BU
#define	CH_0_MULTIPLIERS		0x0DU
#define	CH_1_MULTIPLIERS		0x0FU
#define SYSTEM_FLAGS			0x11U
#define UI_FLAGS			0x12U
#define EVENT_FLAGS			0x14U
#define CH0_ACF_H			0x15U
#define CH0_ACF_L			0x16U
#define CH0_LTA_H			0x17U
#define CH0_LTA_L			0x18U
#define CH0_QRD_H			0x19U
#define	CH0_QRD_L			0x1AU
#define	CH1_ACF_H			0x1BU
#define	CH1_ACF_L			0x1CU
#define	CH1_UMOV_H			0x1DU
#define	CH1_UMOV_L			0x1EU
#define	CH1_LMOV_H			0x1FU
#define	CH1_LMOV_L			0x20U

//#define REGISTER_ADDRESS_CONFIRM_TEST_MODE 0x0FU

#define VDDHI_PIN			15

/***************TIMINGS*********************/


static const nrf_drv_twi_t m_twi_iqs231a = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);

//------------ENUMERATION-------------------//

enum cap_mode{
  CAP_IDLE_STATE = 0,
  CAP_VDDHI_IS_ON_STATE,
  CAP_CONFIRM_ADDRESS_IS_SENT,

};

//--------------FUNCTION PROTOTYPE---------//

uint8_t g_cap_state = CAP_IDLE_STATE;
void IQS231A_confirm_test_mode(void);
void hal_common_init(void);
void switch_on_vddhi_first_function(void);
void cap_sensor_i2c_mode_second_function(void);
void cap_sensor_active_confirm_third_function(void);
void twi_init (void);
//------------GLOBALS---------------------//

//Capacitive sensor state flags

static bool g_cap_vddhi_on_flag = false;
static bool g_cap_confirm_address_flag = false;




void cap_statemachine(void)
{
  switch(g_cap_state){
  case CAP_IDLE_STATE:
  switch_on_vddhi_first_function();
  break;
  case CAP_VDDHI_IS_ON_STATE:
  cap_sensor_i2c_mode_second_function();
  break;
  case CAP_CONFIRM_ADDRESS_IS_SENT:
  cap_sensor_active_confirm_third_function();
  default:
  break;
  
  }

}



/**
 * @brief: Common configuration for LEDs DevKIt pins
 */

void hal_common_init(void)
{

ret_code_t err_code;
  if(!nrf_drv_gpiote_is_init()) {
    nrf_drv_gpiote_init();
  } 
            /****configure P0.22 VDDHI as output********/
  nrf_drv_gpiote_out_config_t oconf = GPIOTE_CONFIG_OUT_SIMPLE(0);
  err_code = nrf_drv_gpiote_out_init(LED_1, &amp;amp;oconf);
  err_code = nrf_drv_gpiote_out_init(LED_2, &amp;amp;oconf);
  err_code = nrf_drv_gpiote_out_init(LED_3, &amp;amp;oconf);
  err_code = nrf_drv_gpiote_out_init(LED_4, &amp;amp;oconf);
  APP_ERROR_CHECK(err_code);
}


void switch_on_vddhi_first_function(void)
{
  
  nrf_gpio_pin_set(VDDHI_PIN);
  nrf_gpio_pin_set(LED_1);
  NRF_LOG_INFO(&amp;quot;VDDHI PIN is HIGH&amp;quot;);
  //put a flag
  g_cap_vddhi_on_flag = false;
  g_cap_state = CAP_VDDHI_IS_ON_STATE;

}



void cap_sensor_i2c_mode_second_function(void)
{
  g_cap_vddhi_on_flag = false;
  ret_code_t err_code;
  uint32_t level;
  uint8_t confirm_addr = REGISTER_ADDR_CONFIRM_TEST_MODE;
  uint8_t data; 

  //level = nrf_gpio_pin_read(VDDHI_PIN);
  level = nrf_gpio_pin_out_read(VDDHI_PIN);
  if(level == true){
   nrf_delay_ms(2); //wait 2 ms, refer to datasheet P. 2
   //IQS231A_I2C_ADDR_TEST_MODE &amp;lt;-----------0x45 slave addredd
   // write 0x0F to 0x45 to confirm test mode and check data
   err_code = nrf_drv_twi_tx(&amp;amp;m_twi_iqs231a, IQS231A_I2C_ADDR_TEST_MODE, &amp;amp;confirm_addr, 1, true);
   NRF_LOG_INFO(&amp;quot;CONFIRM ADDRESS 0x0F IS SENT SUCCESSFULLY&amp;quot;)
   nrf_gpio_pin_set(LED_2);
   APP_ERROR_CHECK(err_code);
   //check if recieving ACK is successful and data is equal to A5
   //set a flag
   g_cap_confirm_address_flag = false;
   //go to third state machine
   g_cap_state = CAP_CONFIRM_ADDRESS_IS_SENT;

  }
}


void cap_sensor_active_confirm_third_function(void)
{
   //g_cap_confirm_address_flag = false;
   ret_code_t err_code;
   uint8_t recieved_data;
   err_code = nrf_drv_twi_rx(&amp;amp;m_twi_iqs231a, IQS231A_I2C_ADDR_TEST_MODE, &amp;amp;recieved_data, 1);
   APP_ERROR_CHECK(err_code);
   nrf_gpio_pin_set(LED_3);
   NRF_LOG_INFO(&amp;quot;the recieved address is %d&amp;quot;, recieved_data);

}


void twi_init(void)
{
   ret_code_t err_code;

    const nrf_drv_twi_config_t twi_iqs231a_config = {
       .scl                = ARDUINO_SCL_PIN,
       .sda                = ARDUINO_SDA_PIN,
       .frequency          = TWI_FREQUENCY_FREQUENCY_K400,//NRF_TWI_FREQ_100K, 
       .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
       .clear_bus_init     = false
    };

    err_code = nrf_drv_twi_init(&amp;amp;m_twi_iqs231a, &amp;amp;twi_iqs231a_config, NULL, NULL);
    APP_ERROR_CHECK(err_code);
    nrf_drv_twi_enable(&amp;amp;m_twi_iqs231a);
}

/**
 * @brief Function for main application entry.
 */
int main(void)
{
 APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
 NRF_LOG_DEFAULT_BACKENDS_INIT();

 NRF_LOG_INFO(&amp;quot;IQS231A is Activated&amp;quot;);
 NRF_LOG_FLUSH();
 cap_statemachine();
 twi_init();
// cap_statemachine(); //check again!
 for(;;) {
        if(NRF_LOG_PROCESS() == false) {
            cap_statemachine();
            }
        }

  	
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;As I mentioned above, when I run the code I get the following signal like this:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-5b760c4a6ec443b4b7e6dcc73035319e/2018_2D00_06_2D00_28-08_5F00_15_5F00_21_2D00_Saleae-Logic-Software.jpg" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you please tell me what am doing wrong, Thanks.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Edit: This is the schematics of my settings. the resistor R/nc is not connected.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-5b760c4a6ec443b4b7e6dcc73035319e/schematics_5F00_cap_5F00_sense.jpg" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI with SDK v14.2.0 and IQS231A</title><link>https://devzone.nordicsemi.com/thread/138041?ContentTypeID=1</link><pubDate>Tue, 26 Jun 2018 19:01:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6e6614cc-1822-4c7b-a7d0-917887468c13</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;You don&amp;#39;t need to consider ack, the driver take care of this for you.&amp;nbsp;I think this thread describe what you want to do:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/11032/i2c-how-do-i-specify-a-register-address-to-read-from-when-calling-nrf_drv_twi_rx"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/11032/i2c-how-do-i-specify-a-register-address-to-read-from-when-calling-nrf_drv_twi_rx&lt;/a&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI with SDK v14.2.0 and IQS231A</title><link>https://devzone.nordicsemi.com/thread/138040?ContentTypeID=1</link><pubDate>Tue, 26 Jun 2018 11:23:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f904763-d887-415f-8380-404857d26cec</guid><dc:creator>Moe</dc:creator><description>&lt;p&gt;Hi Kenneth,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks for your answer, so in the last days i tried to work around a code to make the device entering in test mode so i can initialize the sensor, i tried to build upon the example provided &amp;quot;TWI sensor example, here is my code:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;app_util_platform.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;nrf_drv_twi.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;


#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;

/*************************************************************************/
#include &amp;quot;nrf_drv_gpiote.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;

/* TWI instance ID. */
#define TWI_INSTANCE_ID     0

/******************************IQS231A at test mode**********************************************/
#define IQS231A_I2C_ADDR_TEST_MODE        (0x45U &amp;gt;&amp;gt; 1) //entering test mode aka I2C mode
																										
/********************************OTP test mode RAM addresses*******************************************************/
#define OTP_BANK_0					0x10U  //check setting...it doesnt exist ?
#define OTP__BANK_1 				0x11U 
#define OTP_BANK_2					0x12U
#define OTP_BANK_3					0x13U
/*********************************Memory map I2C reg*********************************************/

#define PRODUCT_NUMBER 			0x00U
#define SOFTWARE_VERSION		0x01U
#define	DEBUG_EVENTS			0x02U
#define COMMANDS				0x04U

#define QUICK_RELEASE			0x08U
#define MOVEMENT				0x09U
#define PROX_THRESHOLDS			0x0BU
#define	CH_0_MULTIPLIERS		0x0DU
#define	CH_1_MULTIPLIERS		0x0FU
#define SYSTEM_FLAGS			0x11U
#define UI_FLAGS				0x12U
#define EVENT_FLAGS				0x14U
#define CH0_ACF_H				0x15U
#define CH0_ACF_L				0x16U
#define CH0_LTA_H				0x17U
#define CH0_LTA_L				0x18U
#define CH0_QRD_H				0x19U
#define	CH0_QRD_L				0x1AU
#define	CH1_ACF_H				0x1BU
#define	CH1_ACF_L				0x1CU
#define	CH1_UMOV_H				0x1DU
#define	CH1_UMOV_L				0x1EU
#define	CH1_LMOV_H				0x1FU
#define	CH1_LMOV_L				0x20U
#define REGISTER_ADDRESS_CONFIRM_TEST_MODE 0x0FU

#define VDDHI_PIN			    22

/***************TIMINGS*********************/
#define T_init					2



/* Indicates if operation on TWI has ended. */
static volatile bool m_xfer_done = false;

/* TWI instance. */
static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);

/* Buffer for samples read from temperature sensor. */
static uint8_t m_sample;

/**
 * @brief Function for switching on VDDHI
 */

void init_vddhi_on(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{

	ret_code_t err_code;
	    if(!nrf_drv_gpiote_is_init()) {
        nrf_drv_gpiote_init();
			}
			
			/****configure P0.22 VDDHI as output********/
			nrf_drv_gpiote_out_config_t vddhi_config = GPIOTE_CONFIG_OUT_SIMPLE(0);
			err_code = nrf_drv_gpiote_out_init(VDDHI_PIN, vddhi_config);
			//nrf_gpio_pin_set(VDDHI_PIN);
			APP_ERROR_CHECK(err_code);
}

/**
 * @brief Function for writing the setting for IQS231A capacitive sensor
 */

void IQS231A_switch_to_test_mode(void)
{

	ret_code_t err_code;
	uint32_t level;
	uint32_t reg[0] = REGISTER_ADDRESS_CONFIRM_TEST_MODE; //0x0F
	
	nrf_gpio_pin_set(VDDHI_PIN);
	level = nrf_gpio_pin_read(VDDHI_PIN);
	
	/*check if device pulled high then initialize the sensor*/
	if(level == true){
		
		
		nrf_delay_ms(T_init); // wait for the cap sensor initialization time
		/**/
    err_code = nrf_drv_twi_tx(&amp;amp;m_twi, IQS231A_I2C_ADDR_TEST_MODE, reg, sizeof(reg), false);
		APP_ERROR_CHECK(err_code);
		
	}
	
	


&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;however, according to the datasheet &lt;a href="https://www.mouser.com/pdfdocs/AZd0981QS231OTPconfiguration-2.pdf"&gt;here&lt;/a&gt;, Page2, section 3 (&amp;quot;Entering Test mode&amp;quot;), i need to read the data and check if data = A5, how can I do this ?&lt;/p&gt;
&lt;p&gt;also the ACK should be recieved, how can i check if ACK is recieved ?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks a lot in advance,&lt;/p&gt;
&lt;p&gt;Mohamed&lt;/p&gt;
&lt;p&gt;Edit: right now VDDHI is connected to&amp;nbsp; a GPIO&lt;/p&gt;
&lt;p&gt;I am using Nordic devkit and VDDHI is connected to pin P0.22&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI with SDK v14.2.0 and IQS231A</title><link>https://devzone.nordicsemi.com/thread/138039?ContentTypeID=1</link><pubDate>Thu, 21 Jun 2018 16:10:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f7069665-966a-4a95-99fa-b891c5ac529d</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hi Moe,&lt;/p&gt;
&lt;p&gt;To find the working 7-bit devices address you can run the TWI scanner example, however if the TWI only is operational for 340ms after power on, you likely will need to power the sensor from a GPIO on the nRF52832, and the toggle this GPIO low between each attempt to interface with the sensor. This will ensure you can discover the correct address to interface the sensor. Once you know the address it should be no problem to write and read any data you like well within the 340ms.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI with SDK v14.2.0 and IQS231A</title><link>https://devzone.nordicsemi.com/thread/138038?ContentTypeID=1</link><pubDate>Thu, 21 Jun 2018 06:41:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:21b50421-5d88-4200-808e-da6164ed7ab4</guid><dc:creator>Moe</dc:creator><description>&lt;p&gt;Here is a schematic for the current cap sense, with a pullup resistors of 4.7K:&lt;/p&gt;
&lt;p&gt;- SCL is routed to pin P0.27.&lt;/p&gt;
&lt;p&gt;-SDA is routed to pin P0.26.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Note: I also also removed the pull-up resistors but it didnt work.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-5b760c4a6ec443b4b7e6dcc73035319e/pastedimage1529563254877v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>