This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nr52832 nfc read and write not working properly with i2c

Hi, I am using nRF52832 with sensor, nfc and  Softdevice S132 v3.0.0 to advertising packets .The sensor is interfaced with nrf52832 using twi interface. I have referred examples\nfc\writable_ndef_msg to read and write data from nfc.  I am writing url to nfc tag and read  it from tag. When I Comment sensor  code , nfc read and write operation work properly. But When I used sensor code then after writing data to tag it reads new data once then it reads old data.

Thanks in Advance

Parents
  • Hi.

    Which sensor are you using?

    Have you tried debugging the project and looked where you end up in the code?

    Best regards,

    Andreas

  • Hi.

    Do you have the opportunity to upgrade to SDK 15.3?

    There has been many workarounds and bug fixes from SDK 12 to SDK 15.3.

    This could fix your problem perhaps.

    Best regards,

    Andreas

  • Thanks for your suggestion. 

    No ,  I don't have opportunity to upgrade SDK.

    But  I can't understand how did twi affect nfc operation ?

  • Hi.

    Could you share the project with me?

    TWI should not affect nfc operations.

    Best regards,

    Andreas

  • static const uint8_t m_url[] =
        {'n', 'o', 'r', 'd', 'i', 'c', 's', 'e', 'm', 'i', '.', 'c', 'o', 'm'}; // URL "nordicsemi.com"
    
    uint8_t       m_ndef_msg_buf[NDEF_FILE_SIZE];                               // Buffer for NDEF file
    volatile bool m_update_state;                                               // Flag indicating that Type 4 Tag performs NDEF message update procedure.
    #define MAX_REC_COUNT      10   //< Maximum records count.
    
    
    #define TWI_INSTANCE_ID     1								/* TWI instance ID. */
    static volatile bool twi_xfer_done = false; /* Indicates if operation on TWI has ended. */
    static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID); /* TWI instance. */
    
    void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context)
    {
    	  switch (p_event->type)
        {
            case NRF_DRV_TWI_EVT_DONE:
                twi_xfer_done = true;
                break;
            default:
                break;
        }
    }
    
    
    
    void twi_init (void)
    {
    		ret_code_t err_code;
    		
        const nrf_drv_twi_config_t twi_lm75b_config = {
           .scl                = 13,
           .sda                = 12,
           .frequency          = NRF_TWI_FREQ_400K,
           .interrupt_priority = APP_IRQ_PRIORITY_HIGHEST,
           .clear_bus_init     = false
        };
    
        err_code = nrf_drv_twi_init(&m_twi, &twi_lm75b_config,twi_handler , NULL); //
        APP_ERROR_CHECK(err_code);
    		
        nrf_drv_twi_enable(&m_twi);
    		
    }
    
    static void advertising_update(void)
    {
        uint32_t      err_code;
        ble_advdata_t advdata;
        uint8_t       flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;
    	ble_advdata_manuf_data_t manuf_specific_data;
    
        manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER;
    		
    	twi_init();
    	set_sensorconfigeration();
    	updateSensorData();
    	nrf_drv_twi_disable(&m_twi);
    	//nrf_drv_twi_uninit(&m_twi);
    				
    		
        manuf_specific_data.data.p_data = (uint8_t *) mf_Data;
        manuf_specific_data.data.size   = mf_Data_LEN;
    		    
        memset(&advdata, 0, sizeof(advdata));
    
        advdata.name_type             = BLE_ADVDATA_FULL_NAME;
    	advdata.include_appearance   = false;
        advdata.flags                 = flags;
    				
        advdata.p_manuf_specific_data = &manuf_specific_data;
    
        err_code = ble_advdata_set(&advdata, NULL);
        APP_ERROR_CHECK(err_code);
    	
    }
    
    
    /**
     * @brief Callback function for handling NFC events.
     */
    static void nfc_callback(void          * context,
                             nfc_t4t_event_t event,
                             const uint8_t * data,
                             size_t          dataLength,
                             uint32_t        flags)
    {
        (void)context;
    
        switch (event)
        {
            case NFC_T4T_EVENT_FIELD_ON:
    						
    						
                break;
    
            case NFC_T4T_EVENT_FIELD_OFF:
    						
              
                m_update_state = false;
                break;
    
            case NFC_T4T_EVENT_NDEF_READ:
                
                break;
    
            case NFC_T4T_EVENT_NDEF_UPDATED:
                if (dataLength == 0)
                {
                    m_update_state = true;
                }
                else if (m_update_state == true)
                {
                    m_update_state = false;
                  
                }
                break;
    
            default:
                break;
        }
    }
    
    
    /**
     * @brief Function for creating a record in English.
     */
    static void en_record_add(nfc_ndef_msg_desc_t * p_ndef_msg_desc)
    {
        /** @snippet [NFC text usage_1] */
        uint32_t             err_code;
        static const uint8_t en_payload[] =
                      {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!'};
    									
    	
        static const uint8_t en_code[] = {'e', 'n'};
    
        	
    	
        NFC_NDEF_TEXT_RECORD_DESC_DEF(en_text_rec,
                                      UTF_8,
                                      en_code,
                                      sizeof(en_code),
                                      en_payload,
                                      sizeof(en_payload));
       /** @snippet [NFC text usage_1] */
    
        err_code = nfc_ndef_msg_record_add(p_ndef_msg_desc,
                                           &NFC_NDEF_TEXT_RECORD_DESC(en_text_rec));
        APP_ERROR_CHECK(err_code);
    
    		bsp_board_led_on(BSP_BOARD_LED_2);
    }
    
    /**
     * @brief Function for encoding the welcome message.
     */
    static void welcome_msg_encode(uint8_t * p_buffer, uint32_t * p_len)
    {
        NFC_NDEF_MSG_DEF(welcome_msg, MAX_REC_COUNT);
    
        en_record_add(&NFC_NDEF_MSG(welcome_msg));
    
        /** @snippet [NFC text usage_2] */
        uint32_t err_code = nfc_ndef_msg_encode(&NFC_NDEF_MSG(welcome_msg),
                                                p_buffer,
                                                p_len);
        APP_ERROR_CHECK(err_code);
    	
    		
        /** @snippet [NFC text usage_2] */
    }
    
    void nfc_init()
    {
    		uint32_t err_code;
    	  /* Set up NFC */
        err_code = nfc_t4t_setup(nfc_callback, NULL);
        APP_ERROR_CHECK(err_code);
    
        /* Provide information about available buffer size to encoding function */
        uint32_t len = sizeof(m_ndef_msg_buf);
    
    
    	 /* Encode welcome message */
        welcome_msg_encode(m_ndef_msg_buf, &len);
    	APP_ERROR_CHECK(err_code);
    
        /* Run Read-Write mode for Type 4 Tag platform */
        err_code = nfc_t4t_ndef_rwpayload_set(m_ndef_msg_buf, sizeof(m_ndef_msg_buf));
        APP_ERROR_CHECK(err_code);
    
        /* Start sensing NFC field */
        err_code = nfc_t4t_emulation_start();
        APP_ERROR_CHECK(err_code);
    
    }
    
    
    int main(void)
    {
    	uint32_t err_code;
    	ble_stack_init();
    	gap_params_init(); 
    	timers_init();
    	advertising_update();
    	timers_start();
        advertising_start();
    	nfc_init();
    	APP_ERROR_CHECK(err_code);
    		
    		
        for (;; )
        {
            power_manage();
    		
        }
    }
    

    snippet of code

  • Hi.

    Could you share the project with me? I'm not able to compile and debug your code snippet.

    Best regards,

    Andreas

Reply Children
Related