Hi All,
I am a beginner,Can you please explain me what is the role of this line?
APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, m_tx_buf, m_length, m_rx_buf, m_length));
Hi All,
I am a beginner,Can you please explain me what is the role of this line?
APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, m_tx_buf, m_length, m_rx_buf, m_length));
nrf_drv_spi
is Nordic SPI driver in their SDK (HAL if you want), see Infocenter documentation for all the details including explanation of all functions, their parameters and structures. As you can notice basically all functions in Nordic SDK return uin32_t
status code (or error code if you want) and macro APP_ERROR_CHECK()
is simple way how to treat all errors (= different return codes then NRF_SUCCESS
) as hard-faults, meaning that application will run to error handler where you can do some logging if you want and then typically soft reset the chip and start from scratch. So every such HAL or SD API call which is essential for your application's state machine (meaning that if it fails you have no easy way to recover and resetting whole OS is the easiest option how to ensure 100% recovery) might be encapsulated into this macro. However you can also just do some switch or if-else structure around that uint32_t return code or just ignore it (not recommended but some peole like it like that...)
For more about SDK error codes read the documentation here, here and of course read header/signature of each SDK function you are using first time;). Btw. macro APP_ERROR_CHECK()
is defined and explained in common error handler module.
nrf_drv_spi
is Nordic SPI driver in their SDK (HAL if you want), see Infocenter documentation for all the details including explanation of all functions, their parameters and structures. As you can notice basically all functions in Nordic SDK return uin32_t
status code (or error code if you want) and macro APP_ERROR_CHECK()
is simple way how to treat all errors (= different return codes then NRF_SUCCESS
) as hard-faults, meaning that application will run to error handler where you can do some logging if you want and then typically soft reset the chip and start from scratch. So every such HAL or SD API call which is essential for your application's state machine (meaning that if it fails you have no easy way to recover and resetting whole OS is the easiest option how to ensure 100% recovery) might be encapsulated into this macro. However you can also just do some switch or if-else structure around that uint32_t return code or just ignore it (not recommended but some peole like it like that...)
For more about SDK error codes read the documentation here, here and of course read header/signature of each SDK function you are using first time;). Btw. macro APP_ERROR_CHECK()
is defined and explained in common error handler module.