Hello! I'm interfacing a sensor with an nRF52840 development board and have run into a few issues:
1) I have a check status function as shown below:
bool ADXL_check_status(int address)
{
ret_code_t err_code;
m_xfer_done = false;
uint8_t reg[1] = {WHO_AM_I_Register};
err_code = nrf_drv_twi_tx(&m_twi, address, reg, sizeof(reg), false);
APP_ERROR_CHECK(err_code);
while (m_xfer_done == false);
m_xfer_done = false;
err_code = nrf_drv_twi_rx(&m_twi, address, &m_sample, sizeof(m_sample));
APP_ERROR_CHECK(err_code);
if(m_sample==(uint8_t)WHO_AM_I_RESPONSE)
{
NRF_LOG_INFO("Device Detected");
return true;
}
else
{
NRF_LOG_INFO("Device Not Detected");
return false;
}
}
If I place a breakpoint on the following line:
if(m_sample==(uint8_t)WHO_AM_I_RESPONSE)
The code will run fine. Obviously, this works fine with debug mode. However, if I take away this debug statement (or I try and program the board, which obviously has no breakpoints), the code goes to the following line in app_error_weak.c:
NRF_BREAKPOINT_COND;
Below is my call stack:
I've tried everything I can think of, including setting the optimization setting to "none" and nothing seems to resolve this issue. Any ideas what might be causing the issue and how to resolve it?
2) I'm trying to scale some sensor data using the following equation:
x * 5 *(2^4) / (2^20-1)
I've tried a number of different methods to get this to work but I think there might be an issue with the pow() function?
This line returns a value of 0:
double scaling_factor = (5*(pow(2,range_val+1)))/(pow(2,20)-1);
This solution returns an infinite value (where x enters the equation with a value of around -9600 or so):
x *= 5;
x *= pow(2,4);
x /= (pow(2,20)-1);
The result is infinite though (multiplying the value by 5 works correctly, multiplying it by 2^4 has no change and the final division sets the value to infinite).
I even tried just multiplying it by the following line:
x *= pow(7.6294,-5);
The value of x in this case doesn't change.
I've tried setting x to be float and double and neither have yielded any changes. Is there something I can do to achieve the desired math function described?
Any help you can give me would be greatly appreciated. Thanks!