<?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>Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/110383/interfacing-between-max86141-and-nrf5340dk</link><description>Hello, 
 
 I&amp;#39;m currently working on using a MAX86141 sensor ( datasheet found here ), and I&amp;#39;ve been running into some issues with communicating with it since this is the first time I&amp;#39;ve used SPI communication before. I&amp;#39;ve gone through the Dev Academy</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 01 May 2024 15:25:01 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/110383/interfacing-between-max86141-and-nrf5340dk" /><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/481388?ContentTypeID=1</link><pubDate>Wed, 01 May 2024 15:25:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5caa8ac0-5a05-4f4e-9c79-7d31e883402f</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;The destination for printing is whatever feature you use normally, hardware serial uart or simply the nRF logger&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;   char Info[120] = &amp;quot;&amp;quot;;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You can use the debugger to look at the contents, or just send &amp;quot;info&amp;quot; as a string to your logger. Length (if needed) is strlen(info). This is an example of using either the nordic uart code or bare metal, but I would suggest just using whatever you normally use.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;   // Transmit ascii packet
   uartSend(InfoPacket, strlen(InfoPacket));

void uartSend(const char * const Packet, const uint32_t PacketLength)
{
#if 0 // Testing on BLE uart Central
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;app_uart.h&amp;quot;
    ret_code_t ret_val;
    for (uint32_t i = 0; i &amp;lt; PacketLength; i++)
    {
        do
        {
            ret_val = app_uart_put(Packet[i]);
            if ((ret_val != NRF_SUCCESS) &amp;amp;&amp;amp; (ret_val != NRF_ERROR_BUSY))
            {
                 return;
            }
        } while (ret_val == NRF_ERROR_BUSY);
    }
#else
   // Bare metal
   if (!NRF_UARTE0-&amp;gt;ENABLE)
   {
      nrf_gpio_pin_set(TX_PIN_NUMBER);
      // Configuration            Direction                Input                          Pullup               Drive Level        Sense Level
      // =====================    =======================  =============================  ===================  =================  =======================
      nrf_gpio_cfg(TX_PIN_NUMBER, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
      nrf_gpio_cfg(RX_PIN_NUMBER, NRF_GPIO_PIN_DIR_INPUT,  NRF_GPIO_PIN_INPUT_CONNECT,    NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
      // Configure the UARTE with no flow control, no parity bit and 230400 baud rate
      NRF_UARTE0-&amp;gt;CONFIG = (UART_CONFIG_HWFC_Disabled   &amp;lt;&amp;lt; UART_CONFIG_HWFC_Pos) | (UART_CONFIG_PARITY_Excluded &amp;lt;&amp;lt; UART_CONFIG_PARITY_Pos);
      NRF_UARTE0-&amp;gt;BAUDRATE = UARTE_BAUDRATE_BAUDRATE_Baud230400 &amp;lt;&amp;lt; UARTE_BAUDRATE_BAUDRATE_Pos;
      // Select TX and RX pins
      NRF_UARTE0-&amp;gt;PSEL.TXD = TX_PIN_NUMBER;
      NRF_UARTE0-&amp;gt;PSEL.RXD = RX_PIN_NUMBER;
      // Enable the UART (starts using the TX/RX pins)
      NRF_UARTE0-&amp;gt;ENABLE = UARTE_ENABLE_ENABLE_Enabled &amp;lt;&amp;lt; UARTE_ENABLE_ENABLE_Pos;
   }
   // Clear CTS which is always set on init regardless of HWFC
   NRF_UARTE0-&amp;gt;EVENTS_CTS = 0;
   // Configure transmit buffer and start the transfer
   NRF_UARTE0-&amp;gt;TXD.MAXCNT = PacketLength;
   NRF_UARTE0-&amp;gt;TXD.PTR    = (uint32_t)Packet;
   NRF_UARTE0-&amp;gt;TASKS_STARTTX = 1;
   // Wait until the transfer is complete
   while (NRF_UARTE0-&amp;gt;EVENTS_ENDTX == 0)
   {
   }
   // Stop the UART TX
   NRF_UARTE0-&amp;gt;TASKS_STOPTX = 1;
   // Wait until we receive the stopped event
   //while (NRF_UARTE0-&amp;gt;EVENTS_TXSTOPPED == 0);
   NRF_UARTE0-&amp;gt;EVENTS_ENDTX = 0;
   NRF_UARTE0-&amp;gt;EVENTS_TXSTOPPED = 0;
   NRF_UARTE0-&amp;gt;EVENTS_TXSTARTED = 0;
   // Disable the UARTE (pins are now available for other use)
   NRF_UARTE0-&amp;gt;ENABLE = UARTE_ENABLE_ENABLE_Disabled &amp;lt;&amp;lt; UARTE_ENABLE_ENABLE_Pos;
#endif
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/481380?ContentTypeID=1</link><pubDate>Wed, 01 May 2024 14:08:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a867021d-2e36-4e54-b5e8-e72b0d40b8f2</guid><dc:creator>Decider</dc:creator><description>&lt;p&gt;When I try to use that example, it says that &amp;quot;Info&amp;quot; is undefined. Is there another directory I need to include or anything extra I should configure in the prj.conf file for that to work properly?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/481349?ContentTypeID=1</link><pubDate>Tue, 30 Apr 2024 20:50:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:112b71af-3ff0-42a6-95c1-80ffc8c4f459</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Not&amp;nbsp; sure about the data you captured, not had time to study, but here&amp;#39;s an example of using structs; keep in mind this may be a distraction though, and is somewhat compiler dependent.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Example 3-byte 24-bit FIFO read
//
//      |------------Byte 0--------------| |--------------Byte 1---------------| |-----------Byte 2------------|
// Id:  |-----Tag Bits----| |--------------------------------ADC Value Bits------------------------------------|
//    |0x1| |-----0x4-----| |-----0x3----| |-------0x4-------| |-------0x5-----| |-----0x6-----| |-----0x7-----| |---Data---|
// Bit:   4   3   2   1   0   18   17   16   15   14   13   12   11   10   9   8   7   6   5   4   3   2   1   0 Tag  ADC
// Data:  1   0   1   0   0    0    1    1    0    1    0    0    0    1   0   1   0   1   1   0   0   1   1   1 0x14 0x34567
// SCLK: 17  18  19  20  21   22   23   24   25   26   27   28   29   30  31  32  33  34  35  36  37  38  39  40
// Name T4A T3A T2A T1A T0A O18A O17A O16A O15A O14A O13A O12A O11A O10A O9A O8A O7A O6A O5A O4A O3A O2A O1A O0A
//
// Tag 0x14, Value 0x34567, Bytes 0xA34567 0xA34567

   // Data received over SPIM
   uint8_t dataBuf[3] = {0xA3,0x45,0x67};
   // Test structure
   fifoUnion_t TestFifo;
   // Copy with reversed endian
   TestFifo.Bytes[0] = dataBuf[2];
   TestFifo.Bytes[1] = dataBuf[1];
   TestFifo.Bytes[2] = dataBuf[0];
   // Print
   snprintf(Info, sizeof(Info), &amp;quot;Tag 0x%02X, Value 0x%05X, Bytes 0x%02X%02X%02X 0x%06X\r\n&amp;quot;, TestFifo.Fifo_24_bit.Tag, TestFifo.Fifo_24_bit.ADC_Value, TestFifo.Bytes[2], TestFifo.Bytes[1], TestFifo.Bytes[0], *(uint32_t*)&amp;amp;TestFifo.Bytes);
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/481325?ContentTypeID=1</link><pubDate>Tue, 30 Apr 2024 15:39:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:21eb2aba-d7ef-4f09-b1fa-31efaad7bce5</guid><dc:creator>Decider</dc:creator><description>&lt;p&gt;Thanks! That does seem to help. For the tag1A and other times that I used /4, I believe that it&amp;#39;s because there are 4 channels the data is being stored in, so it separates the data out into 4 groups like what&amp;#39;s described on page 18 and 19 of the datasheet. I could be wrong about that, but that was how the pseudocode wrote the function and how I understand it to be operating.&lt;/p&gt;
&lt;p&gt;Also, I&amp;#39;ve noticed that while the LED 1 driver still isn&amp;#39;t working even after the changes you suggested, LED 2 and LED 3 are responding as intended. I&amp;#39;ve checked that the LED isn&amp;#39;t bad for LED1 since it works fine when connected to the other drivers. It&amp;#39;s possible that there&amp;#39;s an issue with the sensor itself, but I&amp;#39;ve tried multiple boards now and all of them give the same results so that seems unlikely to me.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve noticed another thing that may or may not be pertinent to what&amp;#39;s going wrong. I have started printing out the values stored in led2A using the following code at the end of the MAX86141_Read_FIFO function:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt; int j;
    for (j = 0; j &amp;lt; FIFO_SAMPLES/4; j++){
        printk(&amp;quot;Value %02X: %02X\n\r&amp;quot;,j,led2A[j]);
    }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and it had been printing out the same values for the data it was &amp;quot;collecting&amp;quot; each time. (I don&amp;#39;t expect the exact numbers to be elucidating, but just in case they are I&amp;#39;ll print the values from led2A here.)&lt;/p&gt;
&lt;table style="border-collapse:collapse;width:32px;" border="0" cellpadding="0" cellspacing="0" height="2601" width="64"&gt;
&lt;tbody&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;width:48pt;" height="20" width="64"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;92&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;9C&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;FF&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;31&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;F5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;D0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;23&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;7C&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0C&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;22&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;A0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;D3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;22&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;8A&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;69&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;1D&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;80&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;61&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;1F&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;28&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;80&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;1C&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;40&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;70&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;C3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;41&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;4B&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;13&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;90&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;53&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;8B&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;70&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;D8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;D0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;50&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;FF&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;FF&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;70&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;61&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;88&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;28&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;21&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;51&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;90&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;48&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0F&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;31&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;63&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;4F&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;24&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;CC&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;A4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;2D&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;81&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;61&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;48&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;A1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;1E&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;21&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;84&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;84&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;42&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;1A&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;A0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;88&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;12&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;50&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;61&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;25&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;6D&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;A2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;89&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;13&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;2A&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;4B&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;96&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;14&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;1C&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0C&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;12&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;18&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td class="xl65" style="height:15.0pt;" height="20"&gt;83&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I made the adjustments that you noted in your response, and now the data is actually changing, but it&amp;#39;s still not collecting in a way that seems right. For instance, now I received the following data during one of the collections:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;table style="border-collapse:collapse;width:48pt;" border="0" cellpadding="0" cellspacing="0" width="64"&gt;
&lt;tbody&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;width:48pt;" align="right" height="20" width="64"&gt;1000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;1000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;1000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;1000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;11000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;11000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;1000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;1000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;1000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;11000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;52525&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;52525&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;129&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;40000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;52525&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;12929&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;20000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" height="20"&gt;24A4A&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;24800&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;49494&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;49494&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;2500&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;14949&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;14949&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" height="20"&gt;24A4A&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height:15.0pt;"&gt;
&lt;td style="height:15.0pt;" align="right" height="20"&gt;29292&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This is very typical for the data that&amp;#39;s collected. A lot of round numbers like 1000, 11000, etc., or numbers with repeating digits like 52525 or 49494 that show up multiple times. The data also doesn&amp;#39;t seem to correspond to the actual stimulus of light on the photodiodes. I&amp;#39;m not sure if this is helpful, but I thought it could help to indicate a potential flaw in the code.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll&amp;nbsp;also&amp;nbsp;take a look at what you&amp;#39;re talking about with big-endian and little-endian, but that&amp;#39;s a new area for me so it might take me a little bit to work through and try to make any adjustments that you mentioned.&lt;/p&gt;
&lt;p&gt;Thanks for all the help you both have given so far! It&amp;#39;s been extremely useful and I appreciate you taking the time to help me try and figure this out!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/481187?ContentTypeID=1</link><pubDate>Tue, 30 Apr 2024 01:18:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3d79fff3-a1d2-4c89-a11a-8dde113931b4</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;I see a number of bugs which you could fix and see if it helps. As an aside, there are other ways to extract the data, though I&amp;#39;m not suggesting you change at this stage. The AFE sends data in 24-bit lumps, MSB-first - which is ok - but in Big-endian order, which is a pain. This is the quoted 3x24-bit transfer:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// MAX86140 MAX86141 MSB first, Big Endian (ARM is generally using Little Endian)
//
//      |------------Byte 0--------------| |--------------Byte 1---------------| |-----------Byte 2------------|
//      |-----Tag Bits----| |--------------------------------ADC Value Bits------------------------------------|
//        4   3   2   1   0   18   17   16   15   14   13   12   11   10   9   8   7   6   5   4   3   2   1   0
//
// SCLK  17  18  19  20  21   22   23   24   25   26   27   28   29   30  31  32  33  34  35  36  37  38  39  40
// SDO  T4A T3A T2A T1A T0A O18A O17A O16A O15A O14A O13A O12A O11A O10A O9A O8A O7A O6A O5A O4A O3A O2A O1A O0A
// SCLK  41  42  43  44  45   46   47   48   49   50   51   52   53   54  55  56  57  58  59  60  61  62  63  64
// SDO  T4B T3B T2B T1B T0B O18B O17B O16B O15B O14B O13B O12B O11B O10B O9B O8B O7B O6B O5B O4B O3B O2B O1B O0B
// ...
// SDO  T4C T3C T2C T1C T0C O18C O17C O16C O15C O14C O13C O12C O11C O10C O9C O8C O7C O6C O5C O4C O3C O2C O1C O0C&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This could be modeled like so:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;typedef struct {
   uint32_t ADC_Value : 19;       // 19-bit value
   uint32_t Tag       :  5;       //  5-bit Tag
}__attribute__((packed)) fifo_24_bit_t;

typedef union {
   fifo_24_bit_t  Fifo_24_bit;         // Treat as 24-bit fifo data
   uint8_t        Bytes[sizeof(fifo_24_bit_t)];            // Treat as an array of bytes
}__attribute__((packed)) fifoUnion_t;

// MAX86140 MAX86141 MSB first, Big Endian (ARM is generally using Little Endian)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Test layout with an example:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Test layout
const fifoUnion_t __packed fifoUnion = {
   .Fifo_24_bit = {
      .Tag       = {0x0},
      .ADC_Value = {0x034567}
   }
};
STATIC_ASSERT(sizeof(fifoUnion) == 3, &amp;quot;fifoUnion_t incorrect size&amp;quot;);

snprintf(Info, sizeof(Info), &amp;quot;Tag 0x%02X, Value 0x%05X, Bytes 0x%02X%02X%02X 0x%06X\r\n&amp;quot;, fifoUnion.Fifo_24_bit.Tag, fifoUnion.Fifo_24_bit.ADC_Value, fifoUnion.Bytes[0], fifoUnion.Bytes[1], fifoUnion.Bytes[2], *(uint32_t*)fifoUnion.Bytes );
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Looking at the log for this example:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Tag 0x00, Value 0x34567, Bytes012 0x674503, treat as word: 0x034567&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This works fine, but incoming data has to be converted to little endian, so don&amp;#39;t bother.&lt;/p&gt;
&lt;p&gt;Here are the bugs:&lt;/p&gt;
&lt;p&gt;read_reg use 8-bit data and 16-bit size:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static int spi_read_reg(uint8_t reg, uint8_t values[], uint16_t size)    // &amp;lt;&amp;lt;== 16-bit size&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;write_reg 8-bit data, 8-bit size:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static int spi_write_reg(uint8_t reg, uint8_t value)                   // &amp;lt;&amp;lt;== 8-bit reg, 8-bit data&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;8-bit data:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void MAX86141_Initialize_AFE(void){
    uint8_t values[3];                   // &amp;lt;&amp;lt;== 8-bit data&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;read_fifo:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;//The FIFO is 128 sample depth and is designed to support various data types. Each sample width is 3 bytes, which includes a 5-bit tag width  &amp;lt;==
void MAX86141_Read_FIFO(void){
    uint8_t values[3];
    uint8_t size = 3;
    int i;
    uint16_t sampleCnt = FIFO_SAMPLES;                 // &amp;lt;&amp;lt;== 16-bit size, play safe
    uint8_t dataBuf[FIFO_SAMPLES*3];                   // &amp;lt;&amp;lt;== 8-bit data
    uint8_t tag1A[FIFO_SAMPLES/4];                     //  &amp;lt;== why /4 instead of /3?&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Not clear why using /4 instead of /3 in many places.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/481139?ContentTypeID=1</link><pubDate>Mon, 29 Apr 2024 14:45:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9f80daa7-ed64-4191-8f12-e02e4b29029b</guid><dc:creator>Decider</dc:creator><description>&lt;p&gt;Certainly! A link to the file on&amp;nbsp;Google Drive&amp;nbsp;&lt;a href="https://drive.google.com/file/d/1Jm7ZSDM4GJHv0JQs5FkLHmNcnNI3Qbdb/view?usp=drive_link"&gt;can be found here&lt;/a&gt;. (If there&amp;#39;s a different preferred place to upload files to, I&amp;#39;m certainly happy to make that adjustment.)&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Yes, I&amp;#39;m using an nRF534 DK, but the LEDs are being controlled by the sensor, not directly by the dk.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If I&amp;#39;m understanding correctly, the LEDs should be controlled by what is written to the LED range registers, the LED pulse amplitude registers, and the LED sequence registers. This takes place in the MAX6141_Initialization_AFE function in my code.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;According to the datasheet, writing 0x3 to 0x2A[1:0] and 0x2A[3:2] will set the LED range for LED 1 and LED 2 to 124mA which I have done by writing 0x0F to 0x2A.&lt;/p&gt;
&lt;p&gt;Then the LED pulse amplitude registers 0x23 and 0x24 for LEDs 1 and 2 are set to 15.36mA by writing 0x20 to each of them. I&amp;#39;m honestly not entirely sure what the difference is between these two currents, but the datasheet uses these values in the pseudocode so they&amp;#39;re what I went with.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Finally, the LED sequence can be set by changing the LED sequence registers 0x20, 0x21, and 0x22, each of which have two sequence registers built in -- the first in [3:0] and the second in [7:4]. The first register set to 0 will reset the sequence. Writing 0x21 to register 0x20 should first pulse LED1, then LED2, and the rest are left at 0 which should end the sequence.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;It&amp;#39;s possible I&amp;#39;m misunderstanding the way some of these work, but even so it follows the way the pseudocode is setup for 2 LEDs and 2 Photodiodes, so I believe I should at least be understanding the expected outcome correctly.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve checked the wiring and had a few other people check it, too, so I think it should be wired correctly for the pins that are being used, but those pins aren&amp;#39;t being used by the dk.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Finally, I&amp;#39;ve been trying to find a usable logic analyzer for this but haven&amp;#39;t had any luck. We do have an old oscilloscope I tried to use, but it&amp;#39;s difficult to get it to check multiple lines at once and make sure the signals are lining up as expected. It does seem to be functioning properly as far as I can tell so far by checking individual signals, however. I&amp;#39;m still trying to see if I can get a better tool to actually make sure that it&amp;#39;s working correctly, though.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best,&lt;/p&gt;
&lt;p&gt;Joe&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/481020?ContentTypeID=1</link><pubDate>Mon, 29 Apr 2024 09:14:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:46c193a7-5266-465a-8e24-03cc0c4c1c43</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;It is difficult to say without seeing your application. Perhaps you can upload it (zip and upload the zipped application folder)? It is a lot easier to navigate than just some snippets.&amp;nbsp;&lt;/p&gt;
[quote user="Decider"]I&amp;#39;m not sure why it&amp;#39;s only LED2, when it should be turning on LED1 and LED2 or why the program still fails partway through[/quote]
&lt;p&gt;So where do you try to turn on the LEDs? The face that one of them isn&amp;#39;t working may indicate that it is not building for the proper target. Perhaps it sets the wrong pin output for the LED.&lt;/p&gt;
&lt;p&gt;What HW are you running on? A&amp;nbsp; DK with the standard LED pin numbers?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Did you try to analyze the SPI pins with a logic analyzer?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/480932?ContentTypeID=1</link><pubDate>Fri, 26 Apr 2024 15:51:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c2f5fbf8-3ba3-44b7-a91a-274288e0836b</guid><dc:creator>Decider</dc:creator><description>&lt;p&gt;I just tried changing every instance of a uint8_t field to a uint16_t, and while the program does keep failing partway through and keeps returning to the message:&lt;/p&gt;
&lt;p&gt;*** Booting nRF Connect SDK v.3.5.99-ncs1 ***&lt;/p&gt;
&lt;p&gt;and then restarting the program, now one of the LEDS is turning on, which definitely helps! I&amp;#39;m not sure why it&amp;#39;s only LED2, when it should be turning on LED1 and LED2 or why the program still fails partway through, but changing the uint8_t definitely seems to have been necessary. Notably, it seems to fail during the &amp;quot;MAX86141_Read_FIFO&amp;quot; function, so there still seems to be another error I&amp;#39;m not seeing in that section.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/480930?ContentTypeID=1</link><pubDate>Fri, 26 Apr 2024 15:40:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3c5c3cab-8762-4d4d-8555-0101cac6d5ed</guid><dc:creator>Decider</dc:creator><description>&lt;p&gt;Yes, thanks! I&amp;#39;ve been trying to fix that, but the things I&amp;#39;ve tried so far haven&amp;#39;t worked. I thought I would just be able to change it to uint16_t, but that causes the program to crash when I try to run it. Do you know how else I could fix this?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/480929?ContentTypeID=1</link><pubDate>Fri, 26 Apr 2024 15:29:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bfa5fc80-3ec7-41ab-97ce-31b902eb9562</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Did you see this post of mine 2 days ago? &amp;quot;&lt;em&gt;Passing a big number in a uint8_t field; the compiler should be showing a warning&lt;/em&gt;&amp;quot;. It&amp;#39;s a major bug in your code.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/480773?ContentTypeID=1</link><pubDate>Thu, 25 Apr 2024 21:18:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e66bdf27-927f-41f4-9d9c-85893d88ef17</guid><dc:creator>Decider</dc:creator><description>&lt;p&gt;For those two lines from the pseudocode, there is a typo. PPG2_ADC_RGE[1:0] is actually at register 0x11[ 5:4]. I have made this adjustment in my code, so that should be okay to my understanding.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t have a logic analyzer with me at the moment, but I&amp;#39;ll see if I can get access to one tomorrow and get back to you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/480604?ContentTypeID=1</link><pubDate>Thu, 25 Apr 2024 08:11:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4810474e-8a50-4741-9b77-fc726faf3352</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;From your reply starting with:&lt;/p&gt;
[quote user="Decider"]Yes, I&amp;#39;m able to build the application with no issues and run the program[/quote]
&lt;p&gt;Regarding the pseudo code from the datasheet, I am not sure what these mean:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;WRITE 0x2 to PPG1_ADC_RGE1:0]; // ADC Range = 16μA (Register 0x11[3:2])
WRITE 0x2 to PPG2_ADC_RGE1:0]; // ADC Range = 16μA (Register 0x11[3:2])&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;On the left hand side it looks like it is supposed to write to two different registers (PPG1_ADC_RGE and PPG2_ADC_RGE), but they use the same register (0x11[3:2]), so I am not sure whether this is a typo or not. You need to check with the developers of the sensor.&lt;/p&gt;
&lt;p&gt;I see that you check the return value of spi_write() and spi_read(), and that it is supposed to write something to the log if it returns anything &amp;lt; 0, which doesn&amp;#39;t seem to be printed. I am not too found of the&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;if (err &amp;lt; 0)
    printk(&amp;quot;Read registers Failed)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;without the {} brackets, but I guess it works.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Can you please try to use a logic analyzer on the SPI pins? Does the CS pin behave as it should? Is the data on the MOSI as expected? And does the reply on the MISO pin as expected? Is it the same as you get when you print the values in the log?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/480551?ContentTypeID=1</link><pubDate>Thu, 25 Apr 2024 01:44:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:778380cc-d660-429d-941d-2fb448424662</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Passing a big number in a uint8_t field; the compiler should be showing a warning for this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define FIFO_SAMPLES 		    128 //0x78

static int spi_read_reg(uint8_t reg, uint8_t values[], uint8_t size)

    uint8_t dataBuf[FIFO_SAMPLES*3];

    spi_read_reg(0x08, dataBuf, sizeof(dataBuf));  &amp;lt;== overflow of uint8_t
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/480538?ContentTypeID=1</link><pubDate>Wed, 24 Apr 2024 20:06:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13520069-84b2-474b-ba86-b4145e2707e2</guid><dc:creator>Decider</dc:creator><description>&lt;p&gt;Just in case it happens to be helpful for some reason, this is the other version of the pseudocode I found from Maxim, but I don&amp;#39;t expect that it will give any particular help with this. I have no idea why it was changed or when it happened, but I figure it won&amp;#39;t hurt to share.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Example pseudo-code for reading data from FIFO when using dual photodiode channels and two LED channels.
void device_data_read(void) {
uint8_t sampleCnt;
uint8_t regVal;
uint8_t dataBuf[128*2*2*3]; //128 FIFO samples, 2 channel, 2 PD, 3 byte/channel
int led1A[32];
int led1B[32];
int led2A[32];
int led2B[32];
ReadReg(0x07, &amp;amp;sampleCnt);
//Read FIFO
ReadFifo(dataBuf, sampleCnt * 3);
int i = 0;
for ( i = 0; i &amp;lt; sampleCnt; i++ ) {
led1A[i] = ((dataBuf[i*12+0] &amp;lt;&amp;lt; 16 ) | (dataBuf[i*12+1] &amp;lt;&amp;lt; 8) | (dataBuf[i*12+2])) &amp;amp; 0x7ffff; // LED1, PD1
led1B[i] = ((dataBuf[i*12+3] &amp;lt;&amp;lt; 16 ) | (dataBuf[i*12+4] &amp;lt;&amp;lt; 8) | (dataBuf[i*12+5])) &amp;amp; 0x7ffff; // LED1, PD2
led2A[i] = ((dataBuf[i*12+6] &amp;lt;&amp;lt; 16 ) | (dataBuf[i*12+7] &amp;lt;&amp;lt; 8) | (dataBuf[i*12+8])) &amp;amp; 0x7ffff; // LED2, PD1
led2B[i] = ((dataBuf[i*12+9] &amp;lt;&amp;lt; 16 ) | (dataBuf[i*12+10] &amp;lt;&amp;lt; 8) | (dataBuf[i*12+11])) &amp;amp; 0x7ffff; // LED2, PD2
}
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/480537?ContentTypeID=1</link><pubDate>Wed, 24 Apr 2024 19:57:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:74e84460-2d8b-419a-97c9-a0f6d9a2dd3b</guid><dc:creator>Decider</dc:creator><description>&lt;p&gt;Shoot, yes. Sorry, I overlooked something when I posted the code again. I had found that the pseudocode from a previous version of the datasheet was different, so I tried making a function using that, but it seems like it was incomplete or incorrect, as you pointed out with the inconsistencies.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The function &amp;quot;MAX86141_Read_FIFO_NEW&amp;quot; is not being used, and instead the&amp;quot;MAX86141_Read_FIFO&amp;quot; function is being used in the code which is the following and should take care of at least the size inconsistency you pointed out, I believe. Apologies for the oversight.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;(For clarity, here is the function actually being used for that portion with the same output when I run it.)&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;void MAX86141_Read_FIFO(void){
    uint8_t values[3];
    uint8_t size = 3;
    int i;
    uint8_t sampleCnt[FIFO_SAMPLES];
    uint8_t dataBuf[FIFO_SAMPLES*3];
    uint8_t tag1A[FIFO_SAMPLES/4];
    uint8_t tag1B[FIFO_SAMPLES/4]; 
    uint8_t tag2A[FIFO_SAMPLES/4];
    uint8_t tag2B[FIFO_SAMPLES/4];
    int led1A[FIFO_SAMPLES/4];
    int led1B[FIFO_SAMPLES/4];
    int led2A[FIFO_SAMPLES/4];
    int led2B[FIFO_SAMPLES/4];

    spi_read_reg(0x07, values, size);
    spi_read_reg(0x08, dataBuf, sizeof(dataBuf));
    for ( i = 0; i &amp;lt; FIFO_SAMPLES/4; i++) {
        tag1A[i] = (dataBuf[i*12+0] &amp;gt;&amp;gt; 3) &amp;amp; 0x1f;
        led1A[i] = ((dataBuf[i*12+0] &amp;lt;&amp;lt; 16) | (dataBuf[i*12+1] &amp;lt;&amp;lt; 8) | dataBuf[i*12+2]) &amp;amp; 0x7ffff; // LED1, PD1
        led1B[i] = ((dataBuf[i*12+3] &amp;lt;&amp;lt; 16) | (dataBuf[i*12+4] &amp;lt;&amp;lt; 8) | dataBuf[i*12+5]) &amp;amp; 0x7ffff; //LED1 PD2
        tag2A[i] = (dataBuf[i*12+6] &amp;gt;&amp;gt; 3) &amp;amp; 0x1f;
        led2A[i] = ((dataBuf[i*12+6] &amp;lt;&amp;lt; 16) | (dataBuf[i*12+7] &amp;lt;&amp;lt; 8) | dataBuf[i*12+8]) &amp;amp; 0x7ffff; //LED1 PD2
        tag2B[i] = (dataBuf[i*12+9] &amp;gt;&amp;gt; 3) &amp;amp; 0x1f;
        led2B[i] = ((dataBuf[i*12+9] &amp;lt;&amp;lt; 16) | (dataBuf[i*12+10] &amp;lt;&amp;lt; 8) | dataBuf[i*12+11]) &amp;amp; 0x7ffff; //LED1 PD2
    }
}  &lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/480534?ContentTypeID=1</link><pubDate>Wed, 24 Apr 2024 19:19:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ecd19c4-262c-4fc4-bb47-ad729b888a6c</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Will try to look closer later, but there are inconsistencies in sizes here - &lt;em&gt;led1A[33]&lt;/em&gt; and onwards&amp;nbsp;overwrites stack:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    uint8_t sampleCnt = 128;

    int led1A[32];

    for ( i = 0; i &amp;lt; sampleCnt; i++){
        led1A[i] = ((dataBuf[i*12+0] &amp;lt;&amp;lt; 16) | (dataBuf[i*12+1] &amp;lt;&amp;lt; 8) | dataBuf[i*12+2]) &amp;amp; 0x7ffff; // LED1, PD1&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/480532?ContentTypeID=1</link><pubDate>Wed, 24 Apr 2024 18:48:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d3be61c9-89a7-4ef2-a5db-db6160fa8829</guid><dc:creator>Decider</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Yes, I&amp;#39;m able to build the application with no issues and run the program. I am getting the expected result when I try to read the Chip ID register (0xFF) which returns 0x25 which is the expected value. When I try to read the FIFO, however, it returns a value of 0. If I try to read other values of the FIFO, 0x08[1] does return a value of F0, but this value never changes and even if it did I don&amp;#39;t think that&amp;#39;s how the FIFO is supposed to handle the data if I&amp;#39;m reading it correctly.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="26071" url="~/f/nordic-q-a/110383/interfacing-between-max86141-and-nrf5340dk/480421"]&lt;blockquote class="quote"&gt;&lt;div class="quote-content"&gt;the program and keeps restarting on the serial monitor&lt;/div&gt;&lt;/blockquote&gt;&lt;div class="quote-footer"&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;This doesn&amp;#39;t happen anymore ever since I made the fixes suggested by hmolesworth, so I think that was an issue caused by the syntax errors.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve modified the code slightly to show more clearly what is and isn&amp;#39;t being read and attached the entirety of that code below and the output I&amp;#39;m getting from it. Almost everything is coming out 0 except the FIFO Data Counter register, which returns 0xF0, the FIFO Data register which on the byte mentioned earlier returns 0xF0, and the Chip ID which returns the expected 0x25. (Note, the code hasn&amp;#39;t changed significantly from the original post besides the fixes pointed out by hmolesworth, but I restructured it to better show the output of what I&amp;#39;m receiving.)&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1713984412653v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;
#include &amp;lt;zephyr/drivers/spi.h&amp;gt;
#include &amp;lt;ncs_version.h&amp;gt;


#define WRITE_EN 0x00
#define READ_EN 0xFF

#define REG_INT_STAT_1         0x00      //Interrupt Status 1
#define REG_INT_STAT_2         0x01      //Interrupt Status 2
#define REG_INT_EN_1           0x02      //Interrupt Enable 1
#define REG_INT_EN_2           0x03      //Interrupt Enable 2
#define REG_FIFO_WR_PTR        0x04      //FIFO Buffer Write Pointer
#define REG_FIFO_RD_PTR        0x05      //FIFO Buffer Read Pointer
#define REG_OVF_COUNTER        0x06      //Over Flow Counter
#define REG_FIFO_DATA_COUNT    0x07      //FIFO Data Counter
#define REG_FIFO_DATA          0x08      //FIFO Data Register

#define REG_FIFO_CONFIG_1      0x09      //FIFO Configuration 1
#define REG_FIFO_CONFIG_2      0x0A      //FIFO Configuration 2
#define REG_MODE_CONFIG        0x0D      //System Control

//Photoplethysmogram (PPG) registers
#define REG_PPG_SYNC_CTRL      0x10      //PPG Sync Control
#define REG_PPG_CONFIG_1       0x11      //PPG Configuration Settings Group 1
#define REG_PPG_CONFIG_2       0x12      //PPG Configuration Settings Group 2
#define REG_PPG_CONFIG_3       0x13      //PPG Configuration Settings Group 3

#define REG_PROX_INTR_THRESH   0x14      //Prox Interrupt Threshold
#define REG_PD_BIAS            0x15      //Photo Diode Bias
#define REG_PICKET_FENCE       0x16      //Picket Fence Settings

#define REG_LED_SEQ_1          0x20      //LED Sequence 1
#define REG_LED_SEQ_2          0x21      //LED Sequence 2
#define REG_LED_SEQ_3          0x22      //LED Sequence 3

#define REG_LED1_PA            0x23      //LED 1 Pulse Amplitude
#define REG_LED2_PA            0x24     //LED 2 Pulse Amplitude
#define REG_LED3_PA            0x25      //LED 3 Pulse Amplitude
#define REG_LED4_PA            0x26      //LED 4 Pulse Amplitude
#define REG_LED5_PA            0x27      //LED 5 Pulse Amplitude
#define REG_LED6_PA            0x28      //LED 6 Pulse Amplitude
#define REG_LED_PILOT_PA       0x29      //LED Pilot Pulse Amplitude
#define REG_LED_RANGE_1        0x2A      //LED Amplitude Range 1
#define REG_LED_RANGE_2        0x2B      //LED Amplitude Range 2

//Hi resolution DAC settings for each LED.
#define REG_S1_HI_RES_DAC1     0x2C
#define REG_S2_HI_RES_DAC1     0x2D
#define REG_S3_HI_RES_DAC1     0x2E
#define REG_S4_HI_RES_DAC1     0x2F
#define REG_S5_HI_RES_DAC1     0x30
#define REG_S6_HI_RES_DAC1     0x31

#define REG_S1_HI_RES_DAC2     0x32
#define REG_S2_HI_RES_DAC2     0x33
#define REG_S3_HI_RES_DAC2     0x34
#define REG_S4_HI_RES_DAC2     0x35
#define REG_S5_HI_RES_DAC2     0x36
#define REG_S6_HI_RES_DAC2     0x37

//Die-temp registers
#define REG_TEMP_CONFIG        0x40
#define REG_TEMP_INTR          0x41
#define REG_TEMP_FRAC          0x42

//SHA256 registers
#define REG_SHA_CMD            0xF0
#define REG_SHA_CONFIG         0xF1

//Memory registers
#define REG_MEM_CTRL           0xF2
#define REG_MEM_IDX            0xF3
#define REG_MEM_DATA           0xF4
#define REG_PART_ID            0xFF

#define SIZE 			        20
#define FIFO_SAMPLES 		    128 //0x78

//Mode 3
static const struct spi_config spi_cfg = {
    .operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8) | SPI_TRANSFER_MSB |
             SPI_MODE_CPOL | SPI_MODE_CPHA,
    .frequency = 125000,
    .slave = 0,
};

/* Mode 0
    .operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8) | SPI_TRANSFER_MSB,
    .frequency = 125000,
*/

#define SPI1_NODE       DT_NODELABEL(my_spi_master)
static const struct device *spi_dev = DEVICE_DT_GET(SPI1_NODE);

#define MY_GPIO1 DT_NODELABEL(gpio1)    //CS
#define GPIO_1_CS       12
const struct device *gpio1_dev = DEVICE_DT_GET(MY_GPIO1);

static int spi_read_reg(uint8_t reg, uint8_t values[], uint8_t size)
{
    int err;

    uint8_t tx_buffer[1];
    tx_buffer[0] = reg;
    
    struct spi_buf tx_spi_bufs[] = {
        { .buf = tx_buffer, .len = sizeof(tx_buffer)},
    };

    struct spi_buf_set spi_tx_buffer_set = {
        .buffers = tx_spi_bufs,
        .count = 1
    };

    struct spi_buf rx_spi_bufs[] = {
        {.buf = values, .len = size,}
    };

    struct spi_buf_set spi_rx_buffer_set = {
        .buffers = rx_spi_bufs,
        .count = 1
    };

    gpio_pin_set(gpio1_dev, GPIO_1_CS, 0);
    do{
        err=spi_write(spi_dev,&amp;amp;spi_cfg,&amp;amp;spi_tx_buffer_set);
        if (err &amp;lt; 0){break;}

        err=spi_read(spi_dev,&amp;amp;spi_cfg,&amp;amp;spi_rx_buffer_set);
    }while (false);
    gpio_pin_set(gpio1_dev, GPIO_1_CS, 1);

    uint8_t data = values[2];
    printk(&amp;quot;Read: 0x%02X\n\r&amp;quot;, data);

    if (err &amp;lt; 0)
        printk(&amp;quot;Read Registers Failed&amp;quot;);
}

static int spi_write_reg(uint8_t reg, uint8_t value)
{
	int err;

	
	uint8_t tx_buf[] = {(reg &amp;amp; 0x7F), value};
	struct spi_buf 		tx_spi_buf 		= {.buf = tx_buf, .len = sizeof(tx_buf)};
	struct spi_buf_set 	tx_spi_buf_set	= {.buffers = &amp;amp;tx_spi_buf, .count = 1};

        gpio_pin_set(gpio1_dev, GPIO_1_CS, 0);
        err=spi_write(spi_dev,&amp;amp;spi_cfg,&amp;amp;tx_spi_buf_set);
        gpio_pin_set(gpio1_dev, GPIO_1_CS, 1);

	if (err &amp;lt; 0) {
		printk(&amp;quot;spi_write_dt() failed, err %d&amp;quot;, err);
		return err;
	}

	return 0;
}

void MAX86141_Initialize_AFE(void){
    uint8_t values[3];
    uint8_t size = 3;
    spi_write_reg(REG_MODE_CONFIG, 0x01);
    k_msleep(1);
    spi_write_reg(REG_MODE_CONFIG, (0x02));
    spi_read_reg(REG_INT_STAT_1, values, size);
    spi_read_reg(REG_INT_STAT_2, values, size);
    spi_write_reg(REG_PPG_CONFIG_1, 0x2B);
    spi_write_reg(REG_PPG_CONFIG_2, 0x0);
    spi_write_reg(REG_PPG_CONFIG_3, 0xC0);
    spi_write_reg(REG_PD_BIAS, 0x11);
    
    spi_write_reg(REG_LED_RANGE_1,0x0F);
    spi_write_reg(REG_LED1_PA, 0x20);
    spi_write_reg(REG_LED2_PA, 0x20);
    spi_write_reg(REG_MODE_CONFIG,0x06);

    spi_write_reg(REG_FIFO_CONFIG_1, 0x0F);
    spi_write_reg(REG_FIFO_CONFIG_2, (0x02));
    spi_write_reg(REG_INT_EN_1, (0x80));
    
    spi_write_reg(REG_LED_SEQ_1, 0x21);
    spi_write_reg(REG_LED_SEQ_2, 0x0);
    spi_write_reg(REG_LED_SEQ_3, 0x0);
    spi_write_reg(REG_MODE_CONFIG, 0x04);
}

void MAX86141_Read_FIFO(void){
    uint8_t values[3];
    uint8_t size = 3;
    int i;
    uint8_t sampleCnt[FIFO_SAMPLES];
    uint8_t dataBuf[FIFO_SAMPLES*3];
    uint8_t tag1A[FIFO_SAMPLES/4];
    uint8_t tag1B[FIFO_SAMPLES/4]; 
    uint8_t tag2A[FIFO_SAMPLES/4];
    uint8_t tag2B[FIFO_SAMPLES/4];
    int led1A[FIFO_SAMPLES/4];
    int led1B[FIFO_SAMPLES/4];
    int led2A[FIFO_SAMPLES/4];
    int led2B[FIFO_SAMPLES/4];

    spi_read_reg(0x07, values, size);
    spi_read_reg(0x08, dataBuf, sizeof(dataBuf));
    for ( i = 0; i &amp;lt; FIFO_SAMPLES/4; i++) {
        tag1A[i] = (dataBuf[i*12+0] &amp;gt;&amp;gt; 3) &amp;amp; 0x1f;
        led1A[i] = ((dataBuf[i*12+0] &amp;lt;&amp;lt; 16) | (dataBuf[i*12+1] &amp;lt;&amp;lt; 8) | dataBuf[i*12+2]) &amp;amp; 0x7ffff; // LED1, PD1
        led1B[i] = ((dataBuf[i*12+3] &amp;lt;&amp;lt; 16) | (dataBuf[i*12+4] &amp;lt;&amp;lt; 8) | dataBuf[i*12+5]) &amp;amp; 0x7ffff; //LED1 PD2
        tag2A[i] = (dataBuf[i*12+6] &amp;gt;&amp;gt; 3) &amp;amp; 0x1f;
        led2A[i] = ((dataBuf[i*12+6] &amp;lt;&amp;lt; 16) | (dataBuf[i*12+7] &amp;lt;&amp;lt; 8) | dataBuf[i*12+8]) &amp;amp; 0x7ffff; //LED1 PD2
        tag2B[i] = (dataBuf[i*12+9] &amp;gt;&amp;gt; 3) &amp;amp; 0x1f;
        led2B[i] = ((dataBuf[i*12+9] &amp;lt;&amp;lt; 16) | (dataBuf[i*12+10] &amp;lt;&amp;lt; 8) | dataBuf[i*12+11]) &amp;amp; 0x7ffff; //LED1 PD2
    }
}   

void MAX86141_Read_FIFO_NEW(void){
    uint8_t sampleCnt = 128;
    uint8_t regVal;
    uint8_t dataBuf[128*2*2*3];
    uint8_t values[3];
    int i = 0;

    int led1A[32];
    int led1B[32];
    int led2A[32];
    int led2B[32];

    spi_read_reg(0x07, values, 3);

    spi_read_reg(0x08, values, 3);

    for ( i = 0; i &amp;lt; sampleCnt; i++){
        led1A[i] = ((dataBuf[i*12+0] &amp;lt;&amp;lt; 16) | (dataBuf[i*12+1] &amp;lt;&amp;lt; 8) | dataBuf[i*12+2]) &amp;amp; 0x7ffff; // LED1, PD1
        led1B[i] = ((dataBuf[i*12+3] &amp;lt;&amp;lt; 16) | (dataBuf[i*12+4] &amp;lt;&amp;lt; 8) | dataBuf[i*12+5]) &amp;amp; 0x7ffff; //LED1 PD2
        led2A[i] = ((dataBuf[i*12+6] &amp;lt;&amp;lt; 16) | (dataBuf[i*12+7] &amp;lt;&amp;lt; 8) | dataBuf[i*12+8]) &amp;amp; 0x7ffff; //LED1 PD2
        led2B[i] = ((dataBuf[i*12+9] &amp;lt;&amp;lt; 16) | (dataBuf[i*12+10] &amp;lt;&amp;lt; 8) | dataBuf[i*12+11]) &amp;amp; 0x7ffff; //LED1 PD2
    }
}   

void main(void)
{

    gpio_pin_configure(gpio1_dev, GPIO_1_CS, GPIO_OUTPUT);
    gpio_pin_set(gpio1_dev, GPIO_1_CS, 1);
    uint8_t values[3];
    uint8_t size = 3;

    printk(&amp;quot;Initilization...\n\r&amp;quot;);
    MAX86141_Initialize_AFE();
    k_sleep(K_MSEC(1000));
    
    printk(&amp;quot;Read data: \n\r&amp;quot;);
    MAX86141_Read_FIFO_NEW();
    printk(&amp;quot;Register 0xFF: &amp;quot;);
    spi_read_reg(REG_PART_ID, values, size);
    printk(&amp;quot;Register 0x07: &amp;quot;);
    spi_read_reg(0x07, values, size);
    k_sleep(K_MSEC(1000));
    printk(&amp;quot;Register 0x08: &amp;quot;);
    spi_read_reg(0x08, values, size);
    uint8_t data = values[1];
    printk(&amp;quot;Register 0x08[1]: %02X\n\r&amp;quot;,data);
    k_sleep(K_MSEC(1000));
    
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/480421?ContentTypeID=1</link><pubDate>Wed, 24 Apr 2024 11:01:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:daaed26d-2fe4-4771-a250-3b520e802732</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user="Decider"]I&amp;#39;ve made these adjustments, but it still seems to be not be functioning correctly, so it seems that the issues went beyond those simple errors.[/quote]
&lt;p&gt;In your application&amp;#39;s current state. Are you able to build the application without build errors/warnings? What do you see when you run the application as it is now? Do you see any data at all from the sensor device? Is there any traffic on the SPI lines?&amp;nbsp;&lt;/p&gt;
[quote user=""]the program and keeps restarting on the serial monitor[/quote]
&lt;p&gt;Does it still do this?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/479811?ContentTypeID=1</link><pubDate>Sat, 20 Apr 2024 14:29:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f9e4bcff-9b63-4043-8fdc-798551b77d72</guid><dc:creator>Decider</dc:creator><description>&lt;p&gt;Oh, thanks! I can&amp;#39;t believe I missed that. I&amp;#39;ve made these adjustments, but it still seems to be not be functioning correctly, so it seems that the issues went beyond those simple errors.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/479794?ContentTypeID=1</link><pubDate>Fri, 19 Apr 2024 22:19:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:156e2452-9710-4a8d-8580-0d25e2811883</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Note all that group of lines in &lt;em&gt;MAX86141_Read_FIFO()&lt;/em&gt; were incorrect (in case you didn&amp;#39;t notice ..)&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;        tag1A[i] = (dataBuf[i*12+0] &amp;gt;&amp;gt; 3) &amp;amp; 0x1f;
        led1A[i] = ((dataBuf[i*12+0] &amp;lt;&amp;lt; 16) | (dataBuf[i*12+1] &amp;lt;&amp;lt; 8) | dataBuf[i*12+2]) &amp;amp; 0x7ffff; //LED1 PD1
        tag1B[i] = (dataBuf[i*12+3] &amp;gt;&amp;gt; 3) &amp;amp; 0x1f;
        led1B[i] = ((dataBuf[i*12+3] &amp;lt;&amp;lt; 16) | (dataBuf[i*12+4] &amp;lt;&amp;lt; 8) | dataBuf[i*12+5]) &amp;amp; 0x7ffff; //LED1 PD2
        tag2A[i] = (dataBuf[i*12+6] &amp;gt;&amp;gt; 3) &amp;amp; 0x1f;
        led2A[i] = ((dataBuf[i*12+6] &amp;lt;&amp;lt; 16) | (dataBuf[i*12+7] &amp;lt;&amp;lt; 8) | dataBuf[i*12+8]) &amp;amp; 0x7ffff; //LED1 PD2
        tag2B[i] = (dataBuf[i*12+9] &amp;gt;&amp;gt; 3) &amp;amp; 0x1f;
        led2B[i] = ((dataBuf[i*12+9] &amp;lt;&amp;lt; 16) | (dataBuf[i*12+10] &amp;lt;&amp;lt; 8) | dataBuf[i*12+11]) &amp;amp; 0x7ffff; //LED1 PD2&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/479793?ContentTypeID=1</link><pubDate>Fri, 19 Apr 2024 22:16:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:abbae198-6b60-4858-8ccc-8e70f7acee69</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Syntax: parenthesis in wrong place, correct line:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt; led1A[i] = ((dataBuf[i*12+0] &amp;lt;&amp;lt; 16) | (dataBuf[i*12+1] &amp;lt;&amp;lt; 8) | dataBuf[i*12+2]) &amp;amp; 0x7ffff; //LED1 PD1&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/479780?ContentTypeID=1</link><pubDate>Fri, 19 Apr 2024 18:20:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d6ac6c8f-eb1a-4fd1-8bae-93154e9eb83b</guid><dc:creator>Decider</dc:creator><description>&lt;p&gt;Thanks for the reply! To make sure that I understand correctly, to solve the truncation in that example I need to write&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;  spi_write_reg(REG_PPG_CONFIG_3, (0x3&amp;lt;&amp;lt;6));&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;to shift it the proper amount so 0x3 will be written on bits [7:6] as specified in the pseudocode, correct? If so, that makes sense and I&amp;#39;ll make sure to check the code for other instances of that happening. I&amp;#39;ve made that correction in my code.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;For the syntax portion, I&amp;#39;m not sure what the right syntax is for this language. Should I write&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;   led1A[i] = {(dataBuf[i*12+0] &amp;lt;&amp;lt; 16), (dataBuf[i*12+1] &amp;lt;&amp;lt; 8), dataBuf[i*12+2])) &amp;amp; 0x7ffff}; // LED1, PD1&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;instead? If so, I&amp;#39;ll make that change and see if it helps anything.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Lastly, I didn&amp;#39;t even notice the issue with the buffer. Thanks for pointing that out! I believe I should be reading from register 0x08 for that line of code, so I&amp;#39;ve made that correction now to see if that helps. The code still isn&amp;#39;t working correctly, but thanks for pointing those issues out!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing between MAX86141 and nRF5340dk</title><link>https://devzone.nordicsemi.com/thread/479772?ContentTypeID=1</link><pubDate>Fri, 19 Apr 2024 16:37:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:20aef09b-74e0-482f-9adf-dea3f96489c9</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Not sure if this will help, but there are a few simple code errors: The first is overflow leading to truncation&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;  spi_write_reg(REG_PPG_CONFIG_3, (0x3&amp;lt;&amp;lt;7)); &amp;lt;&amp;lt;==  truncation&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;next is syntax&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;   led1A[i] = ((dataBuf[i*12+0] &amp;lt;&amp;lt; 16) | (dataBuf[i*12+1] &amp;lt;&amp;lt; 8) | dataBuf[i*12+2])) &amp;amp; 0x7ffff; // LED1, PD1&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;next is incorrect use of a buffer as a register:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    uint8_t dataBuf[FIFO_SAMPLES*3];

    spi_read_reg(0x07, sampleCnt, sizeof(sampleCnt));
    spi_read_reg(dataBuf, sampleCnt3, sizeof(sampleCnt3));&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Since the MAX86141 uses 24-bit transfers, there may be an issue with the design; worth fixing these issues first.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>