Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF5 SDK 15 TWI Scanner example, strange pin layout

Hi,

I have Ublox EVK-NINA-B3 on table, which has totally different pin layout than NRF52 DK (not sure why): https://www.u-blox.com/sites/default/files/EVK-NINA-B3_UserGuide_%28UBX-17056481%29.pdf

It mentions:

SDA, schematic pin GPIO_4, NRF52_pin = P0.16

Your SDK example TWI Scanner contains file: PCA10056_H has only this:

// Arduino board mappings
#define ARDUINO_SCL_PIN 27 // SCL signal pin
#define ARDUINO_SDA_PIN 26 // SDA signal pin
#define ARDUINO_AREF_PIN 2 // Aref pin

Isn't it too bad, after all these years, of NRF5 SDK to put Arduino defines in your official example :-D ?

Anyway, how to map custom pins in this specific case? Your older threads mention some TWI configuration for custom boards, but no defines like TWI0_SCL_PIN do exist in whole SDK. It was only in NRF51.

Thanks,

Cyberluke

Parents
  • Isn't it too bad, after all these years, of NRF5 SDK to put Arduino defines in your official example

    Seems perfectly reasonable to me: these map to the Arduino connectors on on the DK - so it seems obvious to name them, "ARDUINO_..."

    // Arduino board mappings
    #define ARDUINO_SCL_PIN 27 // SCL signal pin
    #define ARDUINO_SDA_PIN 26 // SDA signal pin
    #define ARDUINO_AREF_PIN 2 // Aref pin

    If you look at the DK User Guide, you will see that SCL on the Arduino headers goes to P0.27, and SDA on the Arduino headers goes to P0.26

    So, to use other pins, just change those numbers.

    no defines like TWI0_SCL_PIN do exist in whole SDK

    Presumably because, on the nRF52, you can route the functions to any pin you like.

  • Yes, but I'm developing on DK in order to make firmware for NRF52 unit and for this I only need to setup TWI specific stuff. So it should be portable and written in terms of the best practices for TWI library inside NRF5 SDK 15.2.

    The manufacturer = UBlox and it is big mess. They have custom_board.h in that PDF only and it is split across two pages. I cannot understand, why they cannot provide zip file with headers and just put it inside PDF in a bad way with bad  formatting. Also they mention to put custom_board.h inside NRF SDK/components/boards/ ...which is not portable. Every SDK version, I will have to run recursive diff & merge for these extra files. 

    So question is: Where can I find best practices for NRF5 SDK making custom board and including inside example project? Not polluting SDK folder, which is not under my control?

  • The arduino definitions are intended to be used when the nRF52 Development Kit board is used as a shield together with an Arduino standard motherboard (see this link). I am not sure why the TWI examples uses these definitions. It may be due to simplicity (no need to make new SCL and SDA definitions when it works perfectly well to use the arduino definitions). Also, it doesn't really matter which pins are being used, as long as you connect it correctly to the TWI sensor.

    Regarding board mapping, I think the current approach used in the SDK is a good way of doing it. The examples in the SDK are written in a manner that is independent of the board used, which makes it possible to create one single project, for many different boards.

    This is achieved by being consistent regarding the definition names. E.g. in the TWI scanner example, the definitions ARDUINO_SCL_PIN and ARDUINO_SDA_PIN are used, and if you look at the files components\boards\pca10040.h and components\boards\pca10056.h, both contain these definitions (In this case they are assigned the same pin values, but this is not always the case). Then you can easily switch board by adding the appropriate preprocessor definition, and boards.h will include the correct board mapping. E.g. BOARD_PCA10040 will include the pca10040.h file and make the project compatible with the nRF52832 DK.

    If you can't find your board in components\boards then you would need to create your own custom header file custom_board.h with the appropriate definitions (remember to use the same naming conventions as the example projects).

    Best regards,

    Simon

  • If you can't find your board in components\boards then you would need to create your own custom header file custom_board.h with the appropriate definitions (remember to use the same naming conventions as the example projects).

    ^ THIS. Let me try to ask in more simple way. I have new board and I need to create custom_board.h, but I believe, by best practices, it should not be included in SDK folder. It should be included in project folder. Is it possible? Does it make sense? Then I would not put any preprocessor symbol like BOARD_CUSTOM or BOARD_PCAxxxxx. Would it be correct? 

Reply
  • If you can't find your board in components\boards then you would need to create your own custom header file custom_board.h with the appropriate definitions (remember to use the same naming conventions as the example projects).

    ^ THIS. Let me try to ask in more simple way. I have new board and I need to create custom_board.h, but I believe, by best practices, it should not be included in SDK folder. It should be included in project folder. Is it possible? Does it make sense? Then I would not put any preprocessor symbol like BOARD_CUSTOM or BOARD_PCAxxxxx. Would it be correct? 

Children
  • It's only header file, without any logic. It must be separated from code logic (SDK) in order to easily make transition on another SDK deployment: ie. wipeout NRF5_SDK folder and unzip new NRF5 SDK folder. That's how software architecture & development should be. Layers, modules, separate business logic, etc.

  • I understand your concern. If you create your own custom_board.h file and put it in components\boards, and you share the project file with others, they won't find the file. 

    However, you can still use the approach explained below, while custom_board.h is a part of your project. You do this by placing the custom_board.h file inside examples\peripheral\twi_scanner. Then you simply define BOARD_CUSTOM, and the boards.h will include the file custom_boards.h.

  • I'm not at desktop PC with NRF SDK atm. Just on laptop with Java. From what I remember, the problem was that if you define BOARD_CUSTOM anywhere in the project, some include inside /components/boards will catch this and will want to include custom_board.h file in /components/boards folder, which does not exist here by default. So the app will not compile and will throw fatal error during the build (tried yesterday on SDK 15.2). Any clues? 

    My guess:

    1) Let Nordic include empty custom_board.h themselves in /components/boards

    2) Do not set BOARD_CUSTOM, do not set BOARD_anything in the project

  • I think it's a good thing that a fatal error is thrown when you have defined BOARD_CUSTOM without including the custom_board.h file. Then you get redirected to the line shown below in boards.h. Then you can easily see how to avoid the error, either remove the definition or include the header file. Do you agree?

    #elif defined(BOARD_CUSTOM)
      #include "custom_board.h"

    So you think the example projects would be improved without having the board definitions? If so, how should everything be organized in order to make one project compatible with several boards?

Related