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

Trouble running Adafruit Tag Example on nRF52840 DK

I am trying to use PN532 on nRF52840. Nordic SDK has an example Adafruit Tag Example but it is for nRF52832. I have ported the example but it fails in TWI Communication.

What did I do ?

  • In makefile change every occurrence of pca10040 to pca10056
  • In makefile change every occurrence of nRF52832 to nRF52840
  • Copy sdk_config.h from TWI Scanner example to Adafruit Tag Example

Problems I am facing

LOG :

<error> app: End of error report
<info> app: NFC EXAMPLE Adafruit tag reader started.
<info> adafruit_pn532: Creating I2C
<info> adafruit_pn532: Looking for PN532
<info> adafruit_pn532: Trying to get the firmware version
<info> adafruit_pn532: Trying to send command
<info> adafruit_pn532:  02                     |.
<info> adafruit_pn532: Sending command
<info> adafruit_pn532:  00 00 FF 02 FE D4 02 2A|.......*
<info> adafruit_pn532:  00                     |.
<info> adafruit_pn532: Failed while calling TWI tx 1, err_code = 33282
<info> adafruit_pn532: Failed to write command, err_code = 33282
<info> adafruit_pn532: Failed to send GetFirmwareVersion command, err_code = 33282
<info> adafruit_pn532: Didn't find PN53x board, err_code = 33282
<error> app: ERROR 33282 [NRF_ERROR_DRV_TWI_ERR_DNACK] at ../../../main.c:405
PC at: 0x00004D3B
<error> app: End of error report

I am not able to detect PN532. More precisely TWI command fails to send. The error received is NRF_ERROR_DRV_TWI_ERR_DNACK.

Another strange thing is that on pressing reset nRF doesn't log again.

Parents
  • Hello, 

    Nordic SDK has an example Adafruit Tag Example but it is for nRF52832

    What Nordic SDK are you running? 

    Have you tried to use the TWI scanner app first, to verify that you are able to find PN532?

    Kind regards,
    Øyvind

  • I am using SDK 15.3.0.

    Yes, I first ran TWI Scanner and it detected PN532 at the correct address.

  • Have you compared the makefile, sdk_config.h and other relevant files to a PCA10056 project e.g. the TWI Scanner Application? Please ensure that the linker script is configured correctly (examples\nfc\adafruit_tag_reader\pca10040\blank\armgcc\adafruit_tag_reader_gcc_nrf52.ld). This configures the memory regions of the device. 

    The sdk_config file for the PN532 project includes several application-specific configurations, did you overwrite examples\nfc\adafruit_tag_reader\pca10040\blank\config\sdk_config.h with examples\peripheral\twi_scanner\pca10040\blank\config\sdk_config.h?

  • For makefile :

    I changed every instance of nRF52832 to nRF52840 and pca10040 to pca10056.

    PROJECT_NAME     := adafruit_tag_reader_pca10056
    TARGETS          := nrf52840_xxaa
    OUTPUT_DIRECTORY := _build
    
    SDK_ROOT := ../../../../../..
    PROJ_DIR := ../../..
    
    $(OUTPUT_DIRECTORY)/nrf52840_xxaa.out: \
      LINKER_SCRIPT  := adafruit_tag_reader_gcc_nrf52.ld
    
    # Source files common to all targets
    SRC_FILES += \
      $(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52.S \
      $(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_rtt.c \
      $(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_serial.c \
      $(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_uart.c \
      $(SDK_ROOT)/components/libraries/log/src/nrf_log_default_backends.c \
      $(SDK_ROOT)/components/libraries/log/src/nrf_log_frontend.c \
      $(SDK_ROOT)/components/libraries/log/src/nrf_log_str_formatter.c \
      $(SDK_ROOT)/components/boards/boards.c \
      $(SDK_ROOT)/external/nfc_adafruit_library/adafruit_pn532.c \
      $(SDK_ROOT)/components/libraries/button/app_button.c \
      $(SDK_ROOT)/components/libraries/util/app_error.c \
      $(SDK_ROOT)/components/libraries/util/app_error_handler_gcc.c \
      $(SDK_ROOT)/components/libraries/util/app_error_weak.c \
      $(SDK_ROOT)/components/libraries/fifo/app_fifo.c \
      $(SDK_ROOT)/components/libraries/scheduler/app_scheduler.c \
      $(SDK_ROOT)/components/libraries/timer/app_timer.c \
      $(SDK_ROOT)/components/libraries/uart/app_uart_fifo.c \
      $(SDK_ROOT)/components/libraries/util/app_util_platform.c \
      $(SDK_ROOT)/components/libraries/hardfault/nrf52/handler/hardfault_handler_gcc.c \
      $(SDK_ROOT)/components/libraries/hardfault/hardfault_implementation.c \
      $(SDK_ROOT)/components/libraries/util/nrf_assert.c \
      $(SDK_ROOT)/components/libraries/atomic/nrf_atomic.c \
      $(SDK_ROOT)/components/libraries/balloc/nrf_balloc.c \
      $(SDK_ROOT)/external/fprintf/nrf_fprintf.c \
      $(SDK_ROOT)/external/fprintf/nrf_fprintf_format.c \
      $(SDK_ROOT)/components/libraries/memobj/nrf_memobj.c \
      $(SDK_ROOT)/components/libraries/ringbuf/nrf_ringbuf.c \
      $(SDK_ROOT)/components/libraries/strerror/nrf_strerror.c \
      $(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_twi.c \
      $(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_uart.c \
      $(SDK_ROOT)/modules/nrfx/soc/nrfx_atomic.c \
      $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_gpiote.c \
      $(SDK_ROOT)/modules/nrfx/drivers/src/prs/nrfx_prs.c \
      $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_twi.c \
      $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_twim.c \
      $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_uart.c \
      $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_uarte.c \
      $(SDK_ROOT)/components/libraries/bsp/bsp.c \
      $(PROJ_DIR)/main.c \
      $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT.c \
      $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_Syscalls_GCC.c \
      $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_printf.c \
      $(SDK_ROOT)/modules/nrfx/mdk/system_nrf52.c \
      $(SDK_ROOT)/components/nfc/ndef/generic/message/nfc_ndef_msg.c \
      $(SDK_ROOT)/components/nfc/ndef/parser/message/nfc_ndef_msg_parser.c \
      $(SDK_ROOT)/components/nfc/ndef/parser/message/nfc_ndef_msg_parser_local.c \
      $(SDK_ROOT)/components/nfc/ndef/generic/record/nfc_ndef_record.c \
      $(SDK_ROOT)/components/nfc/ndef/parser/record/nfc_ndef_record_parser.c \
      $(SDK_ROOT)/components/nfc/t2t_parser/nfc_t2t_parser.c \
      $(SDK_ROOT)/components/nfc/t4t_parser/apdu/nfc_t4t_apdu.c \
      $(SDK_ROOT)/components/nfc/t4t_parser/cc_file/nfc_t4t_cc_file.c \
      $(SDK_ROOT)/components/nfc/t4t_parser/hl_detection_procedure/nfc_t4t_hl_detection_procedures.c \
      $(SDK_ROOT)/components/nfc/t4t_parser/tlv/nfc_t4t_tlv_block.c \
    
    # Include folders common to all targets
    INC_FOLDERS += \
      $(SDK_ROOT)/components \
      $(SDK_ROOT)/components/nfc/ndef/parser/record \
      $(SDK_ROOT)/modules/nrfx/mdk \
      $(SDK_ROOT)/components/nfc/ndef/generic/message \
      $(SDK_ROOT)/components/libraries/scheduler \
      $(PROJ_DIR) \
      $(SDK_ROOT)/components/libraries/timer \
      $(SDK_ROOT)/components/libraries/fifo \
      $(SDK_ROOT)/components/libraries/strerror \
      $(SDK_ROOT)/components/nfc/t2t_parser \
      $(SDK_ROOT)/components/nfc/t4t_parser/apdu \
      $(SDK_ROOT)/components/toolchain/cmsis/include \
      $(SDK_ROOT)/components/libraries/util \
      $(SDK_ROOT)/components/libraries/bsp \
      ../config \
      $(SDK_ROOT)/components/nfc/t4t_parser/tlv \
      $(SDK_ROOT)/components/libraries/balloc \
      $(SDK_ROOT)/components/nfc/ndef/generic/record \
      $(SDK_ROOT)/components/libraries/ringbuf \
      $(SDK_ROOT)/components/libraries/hardfault/nrf52 \
      $(SDK_ROOT)/components/nfc/ndef/parser/message \
      $(SDK_ROOT)/components/libraries/hardfault \
      $(SDK_ROOT)/components/libraries/uart \
      $(SDK_ROOT)/components/libraries/log \
      $(SDK_ROOT)/components/nfc/t4t_parser/cc_file \
      $(SDK_ROOT)/components/libraries/button \
      $(SDK_ROOT)/modules/nrfx \
      $(SDK_ROOT)/components/libraries/experimental_section_vars \
      $(SDK_ROOT)/integration/nrfx/legacy \
      $(SDK_ROOT)/external/nfc_adafruit_library \
      $(SDK_ROOT)/components/libraries/delay \
      $(SDK_ROOT)/external/segger_rtt \
      $(SDK_ROOT)/components/nfc/t4t_parser/hl_detection_procedure \
      $(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd \
      $(SDK_ROOT)/components/libraries/atomic \
      $(SDK_ROOT)/components/boards \
      $(SDK_ROOT)/components/libraries/memobj \
      $(SDK_ROOT)/integration/nrfx \
      $(SDK_ROOT)/modules/nrfx/drivers/include \
      $(SDK_ROOT)/modules/nrfx/hal \
      $(SDK_ROOT)/external/fprintf \
      $(SDK_ROOT)/components/libraries/log/src \
    
    # Libraries common to all targets
    LIB_FILES += \
    
    # Optimization flags
    OPT = -O3 -g3
    # Uncomment the line below to enable link time optimization
    #OPT += -flto
    
    # C flags common to all targets
    CFLAGS += $(OPT)
    CFLAGS += -DBOARD_PCA10056
    CFLAGS += -DCONFIG_GPIO_AS_PINRESET
    CFLAGS += -DDEBUG
    CFLAGS += -DFLOAT_ABI_HARD
    CFLAGS += -DNRF52
    CFLAGS += -DNRF52840_XXAA
    CFLAGS += -DNRF52_PAN_74
    CFLAGS += -DSWI_DISABLE0
    CFLAGS += -mcpu=cortex-m4
    CFLAGS += -mthumb -mabi=aapcs
    CFLAGS += -Wall -Werror
    CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
    # keep every function in a separate section, this allows linker to discard unused ones
    CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
    CFLAGS += -fno-builtin -fshort-enums
    
    # C++ flags common to all targets
    CXXFLAGS += $(OPT)
    
    # Assembler flags common to all targets
    ASMFLAGS += -g3
    ASMFLAGS += -mcpu=cortex-m4
    ASMFLAGS += -mthumb -mabi=aapcs
    ASMFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
    ASMFLAGS += -DBOARD_PCA10056
    ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET
    ASMFLAGS += -DDEBUG
    ASMFLAGS += -DFLOAT_ABI_HARD
    ASMFLAGS += -DNRF52
    ASMFLAGS += -DNRF52840_XXAA
    ASMFLAGS += -DNRF52_PAN_74
    ASMFLAGS += -DSWI_DISABLE0
    
    # Linker flags
    LDFLAGS += $(OPT)
    LDFLAGS += -mthumb -mabi=aapcs -L$(SDK_ROOT)/modules/nrfx/mdk -T$(LINKER_SCRIPT)
    LDFLAGS += -mcpu=cortex-m4
    LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
    # let linker dump unused sections
    LDFLAGS += -Wl,--gc-sections
    # use newlib in nano version
    LDFLAGS += --specs=nano.specs
    
    nrf52840_xxaa: CFLAGS += -D__HEAP_SIZE=8192
    nrf52840_xxaa: CFLAGS += -D__STACK_SIZE=8192
    nrf52840_xxaa: ASMFLAGS += -D__HEAP_SIZE=8192
    nrf52840_xxaa: ASMFLAGS += -D__STACK_SIZE=8192
    
    # Add standard libraries at the very end of the linker input, after all objects
    # that may need symbols provided by these libraries.
    LIB_FILES += -lc -lnosys -lm
    
    
    .PHONY: default help
    
    # Default target - first one defined
    default: nrf52840_xxaa
    
    # Print all targets that can be built
    help:
    	@echo following targets are available:
    	@echo		nrf52840_xxaa
    	@echo		sdk_config - starting external tool for editing sdk_config.h
    	@echo		flash      - flashing binary
    
    TEMPLATE_PATH := $(SDK_ROOT)/components/toolchain/gcc
    
    
    include $(TEMPLATE_PATH)/Makefile.common
    
    $(foreach target, $(TARGETS), $(call define_target, $(target)))
    
    .PHONY: flash erase
    
    # Flash the program
    flash: default
    	@echo Flashing: $(OUTPUT_DIRECTORY)/nrf52840_xxaa.hex
    	nrfjprog -f nrf52 --program $(OUTPUT_DIRECTORY)/nrf52840_xxaa.hex --sectorerase
    	nrfjprog -f nrf52 --reset
    
    erase:
    	nrfjprog -f nrf52 --eraseall
    
    SDK_CONFIG_FILE := ../config/sdk_config.h
    CMSIS_CONFIG_TOOL := $(SDK_ROOT)/external_tools/cmsisconfig/CMSIS_Configuration_Wizard.jar
    sdk_config:
    	java -jar $(CMSIS_CONFIG_TOOL) $(SDK_CONFIG_FILE)
    

    For sdk_config.h : 

    I copied sdk_config.h from TWI Scanner for pca10056. There was some code defining parameters for PN532 I copied them from this sdk_config.h  examples\nfc\adafruit_tag_reader\pca10040\blank\config\sdk_config.h

    This is the file I used

    For linker file : 

    I used the linker file from examples\peripheral\twi_scanner\pca10056\blank\armgcc\twi_scanner_gcc_nrf52.ld

  • For makefile:

    Please change the following (- is remove, + is add):

    - $(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52.S \
    + $(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52840.S \
    
    - $(SDK_ROOT)/modules/nrfx/mdk/system_nrf52.c \
    + $(SDK_ROOT)/modules/nrfx/mdk/system_nrf52840.c \
    
    - CFLAGS += -DNRF52
    - CFLAGS += -DNRF52_PAN_74
    
    - ASMFLAGS += -DNRF52
    - ASMFLAGS += -DNRF52_PAN_74


    nrf52 is used for nrf52832, make sure to remove.

    For sdk_config.h

    Comparing the sdk_config.h from twi_scanner (PCA10056) and sdk_config.h from adafruit_tag_reader:

    //adafruit_tag_reader
    #define TWI_DEFAULT_CONFIG_FREQUENCY 104857600
    #define TWI0_USE_EASY_DMA 0
    
    //twi_scanner
    #define TWI_DEFAULT_CONFIG_FREQUENCY 26738688
    #define TWI0_USE_EASY_DMA 1
    
    // <26738688=> 100k 
    // <67108864=> 250k 
    // <104857600=> 400k 

    Also there are several instances included in the adafruit_tag_reader sdk_config.h e.g. APP_SCHEDULER_ENABLED which is not included in PCA10056 sdk_config.h
    I am not sure how important, if important, this is for the application, but could be worth trying. 

    For linker file:

    Yes, this seems ok. 

  • After many trials it is finally working. Here is what I did.

    For Makefile

    I added the recommend changes on top of the changes already made before.

    Please change the following (- is remove, + is add):

    For sdk_config.h

    This time I took sdk_config.h file from example as it is. Didn't change anything into the original file.

    For anyone interested in the project

    Here is the project in a zip.

Reply Children
Related