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

Problem with Event and Interrupt in NRF52 !

Hi Forum! I have to understand NRF52 chip for my job! I used to work with STM32 before. It has "Interrupt" (e.g when I receive one byte via SPI, It generates one "SPI_Rx_Interrupt". I can implement my code in the callback function(read this byte, toggle led....) ) .But with NRF52 chip. I can't read anything similar. NRF52 has "Event". This is a new concept with me!

  • I don't know what is "Event".
  • Do have any relation between "Event" and "Interrupt"? ( I think "Yes" ).
  • How is NRF52 chip can detect when the event occurs? ( If I receive one byte via SPI, how is nrf52 detect it?)
  • How can I creat "My_Event" myself?

I hope devTeam can help me in all my question because NRF52 code example is very hard to learn. Thanks all!

  • Of course there are interrupts under the hood! It's ARM Cortex-M, no magic, so of course HW is giving interrupt calls to execute certain parts of SW if such interrupt happens and there is some interrupt handler configured.

    However most of these low-level interrupts are consumed by the stack (Nordic Soft Device or other if you choose) or by drivers which are using HAL. Therefore all typical SW constructions in example FW projects on nRF5x platform you will see "event handlers" registered in various init functions and then implementing handling of these events as they come asynchronously from lower layers. Under this live interrupts but that's very similar to STM32 HAL and SDK modules, isn't it?

    Finally to how hard is it to understand e.g. SPI Master functionality on nRF52 chip:

    • You can open examples\peripheral\spi\main.c and use nrf_drv_spi driver module as per example. it has one event handler and then few events and function calls which do everything what you ask for: starting transfer, callback when transfer is over. What more you would need?
    • Alternatively if you don't like Nordic SPI Master driver then go to chip specification and see what registers and interrupts are available to build your own flow on lower level. In the end you will read that these "events" are just interrupts which get enabled/disabled/cleared as usually. You can also see how Nordic do it in their driver in components\drivers_nrf\spi_master\nrf_drv_spi.c file.

    And you can go on for all the HW peripherals like SPI/TWI/I2C/RADIO/UART/I2S/PWM/PDM...

    With this knowledge could you give us feedback if there is still something unclear about similarities between nRF5 and STM32 chip designs and SDKs or if it's OK now?

  • And one more specific of nRF5x platform is this "Task and Event" mechanism where you can use different events of different feature blocks (basically interrupts) and link some tasks to any other part of the system once these events happen. You cannot really invent your own because these are more or less HW related but you can through register program some flow (e.g. when SPIM ENDTX happens you can lounch some completely unrelated tasks e.g. PWM or RTC or TIMER start). This might be unique to nRF5 platform but not so much difficult to understand.

  • I was use 1 hour to read your comment and consider the example. I think you are correct. But I have to read the code and program longer to understand all. I was confirm my evolution tomorrow. Thanks for your useful reply !

  • Hi endnode. I was consider all example in the SDK. You are right. I can use event of nrf52 :) Thank for your help. Now I have some new question with softdevice. I hope you can help me!!!

    enum BLE_GAP_EVTS
    {
      BLE_GAP_EVT_CONNECTED  = BLE_GAP_EVT_BASE,    /**< Connection established.                         \n See @ref ble_gap_evt_connected_t.            */
      BLE_GAP_EVT_DISCONNECTED,                     /**< Disconnected from peer.                         \n See @ref ble_gap_evt_disconnected_t.         */
      BLE_GAP_EVT_CONN_PARAM_UPDATE,                /**< Connection Parameters updated.                  \n See @ref ble_gap_evt_conn_param_update_t.    */
      BLE_GAP_EVT_SEC_PARAMS_REQUEST,               /**< Request to provide security parameters.         \n Reply with @ref sd_ble_gap_sec_params_reply.  \n See @ref ble_gap_evt_sec_params_request_t. */
      BLE_GAP_EVT_SEC_INFO_REQUEST,                 /**< Request to provide security information.        \n Reply with @ref sd_ble_gap_sec_info_reply.    \n See @ref ble_gap_evt_sec_info_request_t.   */
      BLE_GAP_EVT_PASSKEY_DISPLAY,                  /**< Request to display a passkey to the user.       \n In LESC Numeric Comparison, reply with @ref sd_ble_gap_auth_key_reply. \n See @ref ble_gap_evt_passkey_display_t. */
      BLE_GAP_EVT_KEY_PRESSED,                      /**< Notification of a keypress on the remote device.\n See @ref ble_gap_evt_key_pressed_t           */
      BLE_GAP_EVT_AUTH_KEY_REQUEST,                 /**< Request to provide an authentication key.       \n Reply with @ref sd_ble_gap_auth_key_reply.    \n See @ref ble_gap_evt_auth_key_request_t.   */
      BLE_GAP_EVT_LESC_DHKEY_REQUEST,               /**< Request to calculate an LE Secure Connections DHKey. \n Reply with @ref sd_ble_gap_lesc_dhkey_reply.  \n See @ref ble_gap_evt_lesc_dhkey_request_t */
      BLE_GAP_EVT_AUTH_STATUS,                      /**< Authentication procedure completed with status. \n See @ref ble_gap_evt_auth_status_t.          */
      BLE_GAP_EVT_CONN_SEC_UPDATE,                  /**< Connection security updated.                    \n See @ref ble_gap_evt_conn_sec_update_t.      */
      BLE_GAP_EVT_TIMEOUT,                          /**< Timeout expired.                                \n See @ref ble_gap_evt_timeout_t.              */
      BLE_GAP_EVT_RSSI_CHANGED,                     /**< RSSI report.                                    \n See @ref ble_gap_evt_rssi_changed_t.         */
      BLE_GAP_EVT_ADV_REPORT,                       /**< Advertising report.                             \n See @ref ble_gap_evt_adv_report_t.           */
      BLE_GAP_EVT_SEC_REQUEST,                      /**< Security Request.                               \n See @ref ble_gap_evt_sec_request_t.          */
      BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST,        /**< Connection Parameter Update Request.            \n Reply with @ref sd_ble_gap_conn_param_update. \n See @ref ble_gap_evt_conn_param_update_request_t. */
      BLE_GAP_EVT_SCAN_REQ_REPORT,                  /**< Scan request report.                            \n See @ref ble_gap_evt_scan_req_report_t. */
      BLE_GAP_EVT_PHY_UPDATE,                       /**< PHY have been updated                           \n See @ref ble_gap_evt_phy_update_t.           */
      BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST,       /**< Data Length Update request.                     \n Reply with @ref sd_ble_gap_data_length_update.\n See @ref ble_gap_evt_data_length_update_request_t. */
      BLE_GAP_EVT_DATA_LENGTH_UPDATE,               /**< LL Data Channel PDU payload length updated.     \n See @ref ble_gap_evt_data_length_update_t. */
    };
    

    above code is in the ble_gap.h file.

    • They are ALL OF EVENT can occur, aren't they? ( do have any exception when I connect?)

    • how can I know sense of event? ( example. I can know BLE_GAP_EVT_CONNECTED occur when connection is establish. But I can't know when does BLE_GAP_EVT_PASSKEY_DISPLAY occur ...). I want to know sense of all event. do have any document for me?

    Thanks you!!!

  • No, these are only BLE GAP layer events. If you go to other Soft Device header files you can see many more. The meaning is in the comments and on Infocenter (Soft Device specification and API), you can spend many hours studying Nordic stack API (if you really want to use it, there are of course other alternatives). Btw. event's you are looking to right now are high-level SW things, I've thought from your initial question that are interested into low-level HW interrupts;)

Related