<?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>How to setup TWI Scanner</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/79516/how-to-setup-twi-scanner</link><description>Hey, 
 I have a custom board with nRF52833. Sensor is connected to: P0.11 (pin 19) - SCL P1.08 (pin 17) - SDA 
 with code below I don&amp;#39;t get any `NRF_SUCCESS` back. 
 I saw here that you must define pins (for eg. P1.08 - PIN 17) as 40 (1x32 + 8). So I</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 16 Sep 2021 08:28:22 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/79516/how-to-setup-twi-scanner" /><item><title>RE: How to setup TWI Scanner</title><link>https://devzone.nordicsemi.com/thread/329750?ContentTypeID=1</link><pubDate>Thu, 16 Sep 2021 08:28:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c76306ec-88dd-466c-9899-dc3259dd223e</guid><dc:creator>Vidar Berg</dc:creator><description>[quote user="Jdeveloper"]Thanks, for some reason if I have connected Macbook Pro M1 via UGREEN USB-C hub and then to j-Link&amp;nbsp; and J-tag it doesn&amp;#39;t go to&amp;nbsp; SUCCESS but if I have my Dell XPS 15 and connect J-link directly to USB it works&amp;nbsp;&lt;span title="Smiley"&gt;&lt;/span&gt;[/quote]
&lt;p&gt;This is strange.. I&amp;#39;m afraid I can&amp;#39;t think of any possible explanations for this kind of behaviour.&lt;/p&gt;
[quote user="Jdeveloper"]I created 2 functions for reading and writing data to registers:[/quote]
&lt;p&gt;&amp;nbsp;Try to make the send and receive buffers &amp;#39;static&amp;#39; or global. buffer_send in write_register() is currently a stack variable which will be freed as soon as the program exits the function. &lt;/p&gt;
&lt;p&gt;Are you using the TWIM API in blocking or non-blocking mode (see &lt;span&gt;&lt;a title="Basic usage" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/hardware_driver_twi.html?cp=8_1_2_0_17_1#hardware_driver_twi_basic"&gt;Basic usage&lt;/a&gt;&lt;/span&gt;)? In case of the latter you have to make sure the previous transaction is complete before starting the next. I.e. you can&amp;#39;t have multiple write_register() calls in a row with no delay in-between. The SDK TWI sensor example uses the &amp;#39;m_xfer_done&amp;#39; for this purpose.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to setup TWI Scanner</title><link>https://devzone.nordicsemi.com/thread/329552?ContentTypeID=1</link><pubDate>Wed, 15 Sep 2021 08:32:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7095b442-b5ae-4cb5-a806-3d56f2da1831</guid><dc:creator>Jdeveloper</dc:creator><description>&lt;p&gt;Thanks, for some reason if I have connected Macbook Pro M1 via UGREEN USB-C hub and then to j-Link&amp;nbsp; and J-tag it doesn&amp;#39;t go to&amp;nbsp; SUCCESS but if I have my Dell XPS 15 and connect J-link directly to USB it works&amp;nbsp;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f603.svg" title="Smiley"&gt;&amp;#x1f603;&lt;/span&gt;&lt;br /&gt;Don&amp;#39;t know why since debug works fine..&lt;br /&gt;So now I must find out how to read data from sensor :D Can you maybe help me with that? In the original question I have datasheet for MAX86916 that is almost the same as MAX86915.&lt;/p&gt;
&lt;p&gt;I created 2 functions for reading and writing data to registers:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t read_register(uint8_t reg, uint8_t * p_data, uint32_t length)
{
    uint32_t err_code;
    err_code = nrfx_twim_tx(&amp;amp;m_twi, MAX86915_ADDRESS, &amp;amp;reg, 1, false);
    if(err_code != NRF_SUCCESS) return err_code;

    
    err_code = nrfx_twim_rx(&amp;amp;m_twi, MAX86915_ADDRESS, p_data, length);
    if(err_code != NRF_SUCCESS) return err_code;
    return err_code;
}

uint32_t write_register(uint8_t reg_address, uint8_t data)
{
    nrfx_err_t err_code; 
    uint8_t buffer_send[2] = {reg_address, data};
		
    err_code = nrfx_twim_tx(&amp;amp;m_twi, MAX86915_ADDRESS, buffer_send, sizeof(buffer_send), true);
    APP_ERROR_CHECK(err_code);
	
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Then I have Init and reset functions for it:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;void MAX86915_init (void)
{
    uint8_t revID; 
    uint8_t partID;
    nrfx_err_t err_code;
    err_code  = read_register (PART_ID, &amp;amp;partID,sizeof(partID));
		APP_ERROR_CHECK(err_code);
	
    NRF_LOG_INFO(&amp;quot;MAX86915 PART ID: 0x%02x \r\n&amp;quot;, partID);
    
	
    err_code = read_register (REV_ID, &amp;amp;revID,sizeof(revID));
		APP_ERROR_CHECK(err_code);
	
    NRF_LOG_INFO(&amp;quot;MAX86915 REV ID: 0x%02x \r\n&amp;quot;, revID);
}

void MAX86915_reset (void)
{	
    write_register(MODE_CONF, 0x40);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and lastly setup where I set up what should sensor do. I want to measure&amp;nbsp;continuously.&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void MAX86915_setup (void)
{
    write_register(INT_ENABLE_1, 0xC0);
    
    write_register(FIFO_WR_PTR, 0x00);	// Reset FIFO Write pointer
    write_register(OVERFLOW_CTR, 0x00); // Reset OVERFLOW_CTR pointer
    write_register(FIFO_RD_PTR, 0x00); 	// Reset FIFO READ pointer
    
    write_register(FIFO_CONF, 0x4F); //average sampling  = 4
    write_register(MODE_CONF, 0x03); // ADC range = 4096nA | Sampling Rate = 100 Hz | LED pulseWidth = 411uS
    
    write_register(SPO2_CONF, 0x27); // 400 samples per second
    write_register(LED1_PA, 0x5F); // LED1 current = 19 mA 
    write_register(LED2_PA, 0x5F); // LED2 current = 19 mA 
    write_register(LED3_PA, 0x5F); // LED1 current = 19 mA 
    write_register(LED4_PA, 0x5F); // LED2 current = 19 mA 
    write_register(PILOT_PA, 0x7F); // Pilot LED ~ 25mA
    write_register(LED_SEQ1, 0x21);
    write_register(LED_SEQ2, 0x43); 
}&lt;/pre&gt;&lt;br /&gt;With last 2 lines I enable all leds (LED&amp;#39;s do turn on and I can see them)&lt;br /&gt;&lt;br /&gt;So now for measuring:&lt;br /&gt;As I understand I can see data in FIFO_DATA register at 0x07.&lt;br /&gt;But how do I read it? I have to create matrix because of 4 samples?&lt;br /&gt;Is not just as easy as reading (3 bytes per data item - I suppose data item is one led) fifo data register and just take 4 led data from there?&lt;br /&gt;&lt;br /&gt;So I have simple code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void read_fifo()
{
    uint8_t clearINT1;
    uint32_t LEDdata1=0;
    uint32_t LEDdata2=0;
    uint32_t LEDdata3=0;
    uint32_t LEDdata4=0;
    uint8_t dataArray[12];
   
    nrfx_err_t err_code;

    //Clear Interrupts
    err_code = read_register(INT_STATUS_1, &amp;amp;clearINT1,sizeof(clearINT1));
    
    //read from FIFO_DATA
    err_code =read_register(FIFO_DATA,dataArray,sizeof(dataArray));
    APP_ERROR_CHECK(err_code);	


    //Parse data like that?
    LEDdata1=dataArray[0]&amp;lt;&amp;lt;16|dataArray[1]&amp;lt;&amp;lt;8 |dataArray[2];
    LEDdata2=dataArray[3]&amp;lt;&amp;lt;16|dataArray[4]&amp;lt;&amp;lt;8 |dataArray[5];
    LEDdata3=dataArray[6]&amp;lt;&amp;lt;16|dataArray[7]&amp;lt;&amp;lt;8 |dataArray[8];
    LEDdata4=dataArray[9]&amp;lt;&amp;lt;16|dataArray[10]&amp;lt;&amp;lt;8 |dataArray[11];
  

    //HERE PUSH IT TO MOBILE PHONE WITH BLE
}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I get some weird data, so I suppose this is not the way to fetch data from register.&lt;br /&gt;I also found&amp;nbsp;&lt;a href="https://github.com/ianmacd/d2s/blob/d1d4fb4aa21d6f4c9b9f36caf15bc1a3c21d4e39/drivers/optics/max86915.c#L3266"&gt;this library with read_fifo_data function on line 3266&lt;/a&gt;&amp;nbsp;and it seems I have to do a lot more work?&lt;br /&gt;so on first pass I get 4 samples for LED1 and on second 4 samples for LED2 etc. or what? I&amp;#39;m a bit lost..&lt;/p&gt;
&lt;p&gt;This is maybe off topic, but I want to send data to my mobile device.. I used to use HC-06 for that and I usually just send data to serial and all data goes to phone.. What could be the best alternative since that is not BT device?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to setup TWI Scanner</title><link>https://devzone.nordicsemi.com/thread/329255?ContentTypeID=1</link><pubDate>Mon, 13 Sep 2021 13:38:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:394ae8ed-21ae-4525-93e1-cc0efc1aede3</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;11 and 40 corresponds to P0.11 and P1.08 respectively so your pin assignments appear to be correct at least. But I would still recommend you use the NRF_GPIO_PIN_MAP() macro when assigning pins on PORT 1 as it ensures that the register value always get correctly encoded plus it helps improve the code readability a bit. E.g.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .scl&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = NRF_GPIO_PIN_MAP(0,11), // P0.11&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .sda&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = NRF_GPIO_PIN_MAP(1,08), //P1.08&lt;/p&gt;
&lt;p&gt;Is the sensor already mounted on your custom board, or is it connected externally via cables? And do you have the same supply voltage on both the MAX86915 and the nRF52?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>