<?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>Assertion Failed - PCA100040</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/106729/assertion-failed---pca100040</link><description>I am coding NRF52832 to send ADC values to the NFC tools app using the NFC ndef_message (SEGGER). I am using SDK v17.1.0. I can build the code, but when I run the code, I get the following error. 
 ASSERTION FAILED at C:\nrf_sdk\modules\nrfx\drivers\src</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 04 Jan 2024 15:06:57 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/106729/assertion-failed---pca100040" /><item><title>RE: Assertion Failed - PCA100040</title><link>https://devzone.nordicsemi.com/thread/462743?ContentTypeID=1</link><pubDate>Thu, 04 Jan 2024 15:06:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc4ede3b-03c4-46db-9353-68bf9a5f218f</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;br /&gt;&lt;br /&gt;Thank you for your patience with this.&lt;br /&gt;&lt;br /&gt;I am glad to hear that you were able to successfully test the NFC samples, since this gives us a strong indication that the issue is with the source code.&lt;br /&gt;&amp;nbsp;&lt;br /&gt;Before I start the review I thought I should asl : Do you still require support with this?&lt;br /&gt;Just in case you&amp;#39;ve already found the root cause of your issue in the time since we last spoke.&lt;br /&gt;&lt;br /&gt;If you do still require support with this, could you please specify which error code that is returned when the NFC fails to initialize?&lt;br /&gt;Please make sure to have DEBUG defined in your preprocessor defines, like shown in the included image, to have the logger module output an error message whenever a non-NRF_SUCCESS error code is passed to an APP_ERROR_CHECK.&lt;br /&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/7750.enabling_5F00_debug_5F00_SES.PNG" /&gt;&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Assertion Failed - PCA100040</title><link>https://devzone.nordicsemi.com/thread/462189?ContentTypeID=1</link><pubDate>Tue, 02 Jan 2024 06:50:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dd6fed53-b307-422a-a5e6-539791276b83</guid><dc:creator>Samiya Khaliq</dc:creator><description>&lt;p&gt;Sure, I can wait.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Assertion Failed - PCA100040</title><link>https://devzone.nordicsemi.com/thread/461749?ContentTypeID=1</link><pubDate>Wed, 27 Dec 2023 09:52:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:084b78b9-15d7-4b94-a39f-01a8eaad0017</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;&lt;span&gt;&lt;span dir="ltr"&gt;Hello,&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span dir="ltr"&gt;We are severely understaffed this week because of the Christmas holidays, and Karl will have to get back to you on this next week. Sorry for the inconvenience.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span dir="ltr"&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Assertion Failed - PCA100040</title><link>https://devzone.nordicsemi.com/thread/461644?ContentTypeID=1</link><pubDate>Sun, 24 Dec 2023 12:16:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:75e198d6-dd9e-4af3-b0cc-9f567515eb62</guid><dc:creator>Samiya Khaliq</dc:creator><description>&lt;p&gt;I ran the NFC examples, and they work fine. I also replaced my main.c file with those examples to check if my sdk_config.h file is working fine, and it does. So, the problem is in my code. It fails to initialize NFC.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Assertion Failed - PCA100040</title><link>https://devzone.nordicsemi.com/thread/461489?ContentTypeID=1</link><pubDate>Thu, 21 Dec 2023 16:29:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64ecebac-de82-4cec-81e3-1a18bd269690</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Have you verified that the NFC is initialized as expected?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Assertion Failed - PCA100040</title><link>https://devzone.nordicsemi.com/thread/461478?ContentTypeID=1</link><pubDate>Thu, 21 Dec 2023 15:25:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:443cbd14-8b86-44ad-a08c-404cc5ba8d75</guid><dc:creator>Samiya Khaliq</dc:creator><description>&lt;p&gt;I have added the&amp;nbsp;&lt;span&gt;nrfx_saadc_config_t struct. The code builds and runs, but no NFC is detected on my NFC tools app.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;quot;nfc_t2t_lib.h&amp;quot;
#include &amp;quot;nfc_ndef_msg.h&amp;quot;
#include &amp;quot;nfc_text_rec.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;nrfx_saadc.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;

#define MAX_REC_COUNT 3  /**&amp;lt; Maximum records count. */
#define NFC_TEXT_BUF_SIZE 20  /**&amp;lt; Maximum size of the NFC text buffer. */

/* Buffer used to hold an NFC NDEF message. */
uint8_t m_ndef_msg_buf[256];

/* Buffer used to hold the NFC text. */
static uint8_t m_nfc_text_buf[NFC_TEXT_BUF_SIZE];

/* NFC module initialization status */
static bool nfc_initialized = false;

/* Callback function for handling NFC events. */
static void nfc_callback(void* p_context, nfc_t2t_event_t event, const uint8_t* p_data, size_t data_length)
{
    (void)p_context;

    switch (event)
    {
        case NFC_T2T_EVENT_FIELD_ON:
            bsp_board_led_on(BSP_BOARD_LED_0);
            break;
        case NFC_T2T_EVENT_FIELD_OFF:
            bsp_board_led_off(BSP_BOARD_LED_0);
            break;
        default:
            break;
    }
}

/* Function declaration for nrfx_saadc_event_handler */
void nrfx_saadc_event_handler(nrfx_saadc_evt_t const * p_event);

/* Function for initializing logging. */
static void log_init(void)
{
    ret_code_t err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();
}

/* Function for reading ADC value using nrfx SAADC. */
static uint16_t read_adc_value(void)
{
    ret_code_t err_code;
    nrf_saadc_value_t adc_value;

    // Sample conversion
    err_code = nrfx_saadc_sample_convert(0, &amp;amp;adc_value);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_INFO(&amp;quot;ADC Value: %d&amp;quot;, adc_value);

    return adc_value;
}

/* Function definition for nrfx_saadc_event_handler */
void nrfx_saadc_event_handler(nrfx_saadc_evt_t const * p_event)
{
    if (p_event-&amp;gt;type == NRFX_SAADC_EVT_DONE)
    {
        // Check if SAADC conversion was successful
        if (p_event-&amp;gt;data.done.p_buffer != NULL)
        {
            // SAADC conversion successful, handle the result if needed
            // Access the buffer with p_event-&amp;gt;data.done.p_buffer
            NRF_LOG_INFO(&amp;quot;SAADC conversion successful&amp;quot;);
        }
        else
        {
            // SAADC conversion failed
            NRF_LOG_ERROR(&amp;quot;SAADC conversion failed&amp;quot;);
        }

        // Restart SAADC conversion for continuous sampling
        ret_code_t err_code = nrfx_saadc_buffer_convert(NULL, 1);
        APP_ERROR_CHECK(err_code);
    }
    else if (p_event-&amp;gt;type == NRFX_SAADC_EVT_LIMIT)
    {
        // Handle SAADC limit event (if needed)
        // This event occurs when the sampled value goes beyond the set limits
        NRF_LOG_WARNING(&amp;quot;SAADC limit event&amp;quot;);
    }
}


/* ADC message encoding function */
static ret_code_t adc_msg_encode(uint8_t* p_buffer, uint32_t* p_len)
{
    ret_code_t err_code;

    // Read ADC value here (replace this with your ADC reading logic)
    uint16_t adc_value = read_adc_value();

    // Convert ADC value to ASCII
    snprintf((char*)m_nfc_text_buf, sizeof(m_nfc_text_buf), &amp;quot;%d&amp;quot;, adc_value);

    /* Create NFC NDEF text record description in English */
    NFC_NDEF_TEXT_RECORD_DESC_DEF(nfc_en_text_rec,
                                  UTF_8,
                                  (uint8_t*)&amp;quot;en&amp;quot;,
                                  2,
                                  m_nfc_text_buf,
                                  strlen((char*)m_nfc_text_buf));

    /* Create NFC NDEF message description, capacity - MAX_REC_COUNT records */
    NFC_NDEF_MSG_DEF(nfc_text_msg, MAX_REC_COUNT);

    /* Add text records to NDEF text message */
    err_code = nfc_ndef_msg_record_add(&amp;amp;NFC_NDEF_MSG(nfc_text_msg), &amp;amp;NFC_NDEF_TEXT_RECORD_DESC(nfc_en_text_rec));
    APP_ERROR_CHECK(err_code);

    /* Encode NDEF message */
    err_code = nfc_ndef_msg_encode(&amp;amp;NFC_NDEF_MSG(nfc_text_msg), p_buffer, p_len);
    return err_code;
}

/* Function for application main entry. */
int main(void)
{
    uint32_t len = sizeof(m_ndef_msg_buf);
    ret_code_t err_code;

    // Initialize logging
    log_init();

    // Initialize nrfx SAADC with configuration
    nrfx_saadc_config_t saadc_config = {
        .resolution = NRF_SAADC_RESOLUTION_10BIT,
        .oversample = NRF_SAADC_OVERSAMPLE_DISABLED,
        .interrupt_priority = NRFX_SAADC_CONFIG_IRQ_PRIORITY,
        .low_power_mode = false
    };

    err_code = nrfx_saadc_init(&amp;amp;saadc_config, nrfx_saadc_event_handler);
    APP_ERROR_CHECK(err_code);

    // Set up NFC
    err_code = nfc_t2t_setup(nfc_callback, NULL);
    APP_ERROR_CHECK(err_code);

    // NFC module is initialized
    nfc_initialized = true;

    // Configure LED-pins as outputs
    bsp_board_init(BSP_INIT_LEDS);

    // Initialize SAADC channel once during initialization
    nrf_saadc_channel_config_t channel_config = NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0);
    channel_config.gain = NRF_SAADC_GAIN1_6;
    err_code = nrfx_saadc_channel_init(0, &amp;amp;channel_config);
    APP_ERROR_CHECK(err_code);

    // Start SAADC conversion for continuous sampling
    err_code = nrfx_saadc_buffer_convert(NULL, 1);
    APP_ERROR_CHECK(err_code);

    while (1)
    {
        // Check if the SAADC is not busy before starting a new conversion
        if (!nrfx_saadc_is_busy())
        {
            // Read ADC value
            uint16_t adc_value = read_adc_value();

            // Encode ADC message
            err_code = adc_msg_encode(m_ndef_msg_buf, &amp;amp;len);
            APP_ERROR_CHECK(err_code);

            // Check if NFC is initialized before setting the payload
            if (nfc_initialized)
            {
                // Set created message as the NFC payload
                err_code = nfc_t2t_payload_set(m_ndef_msg_buf, len);
                APP_ERROR_CHECK(err_code);
            }

            NRF_LOG_FLUSH();
        }

        // Sleep or perform other tasks
        __WFE();
    }
}
&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Assertion Failed - PCA100040</title><link>https://devzone.nordicsemi.com/thread/460675?ContentTypeID=1</link><pubDate>Sun, 17 Dec 2023 18:37:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1e519c37-cde2-4177-bf19-6d659bef4a13</guid><dc:creator>luckyyorange</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;The problem is on line 171 of main.c where you pass NULL as a parameter. The nrfx_saadc_init function asserts the p_config parameter at line 216 of nrf_saadc.c and evaluates to false when given NULL since the saadc requires important configurations before being used.&amp;nbsp;Thus, the runtime assertion failed error is thrown. A nrfx_saadc_config_t struct must be populated with the desired resolution, oversampling, power mode, and interrupt priority field configurations and then passed as a pointer in place of the NULL.&lt;/p&gt;
&lt;p&gt;Hope this help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>