举例:我有一个int a=1;然后我们想在log中打印出a的值的信息,将以下的语句写入你想打印的地方。
//LOG打印数值信息
NRF_LOG_INFO("My float number: " NRF_LOG_FLOAT_MARKER "\r\n", NRF_LOG_FLOAT(a));
NRF_LOG_FLUSH();
a为变量,以上两个语句可以在nrf_log.h 中定义,其中val就是填入参数(a)的地方
以下是在nrf_log.h 中中找到的定义,没有的可以自己添加,有的就不用添加直接用就好
/**
* @brief Macro to be used in a formatted string to a pass float number to the log.
*
* Use this macro in a formatted string instead of the %f specifier together with
* @ref NRF_LOG_FLOAT macro.
* Example: NRF_LOG_INFO("My float number" NRF_LOG_FLOAT_MARKER "\r\n", NRF_LOG_FLOAT(f)))
*/
#define NRF_LOG_FLOAT_MARKER "%s%d.%02d"
/**
* @brief Macro for dissecting a float number into two numbers (integer and residuum).
*/
#define NRF_LOG_FLOAT(val) (uint32_t)(((val) < 0 && (val) > -1.0) ? "-" : ""), \
(int32_t)(val), \
(int32_t)((((val) > 0) ? (val) - (int32_t)(val) \
: (int32_t)(val) - (val))*100)
//LOG打印数值启动信息
NRF_LOG_INFO("My float number: " NRF_LOG_FLOAT_MARKER "\r\n", NRF_LOG_FLOAT(a));
NRF_LOG_FLUSH();
这样就可以在RTT中打印我们想要输出的参数的浮点数值了