I am using SPI0 of nrf52.Following is the code:
I am using SPI0 of nrf52.Following is the code:
Can you please try to tidy up your code? Remove all the code that is not necessary and show us how exactly you are initiating the SPI and how you do read and write operations.
But I am facing Problem in writing the values into the ADXL362 registers using SPI_master code of nrf52. I am using UART for displaying register values on terminal.This is my main function:
int main(void)
{
// Setup bsp module.
bsp_configuration();
LEDS_CONFIGURE(LEDS_MASK);
LEDS_OFF(LEDS_MASK);
uint32_t err_code;
const app_uart_comm_params_t comm_params =
{
RX_PIN_NUMBER,
TX_PIN_NUMBER,
RTS_PIN_NUMBER,
CTS_PIN_NUMBER,
APP_UART_FLOW_CONTROL_ENABLED,
false,
UART_BAUDRATE_BAUDRATE_Baud115200
};
APP_UART_FIFO_INIT(&comm_params,
UART_RX_BUF_SIZE,
UART_TX_BUF_SIZE,
uart_error_handle,
APP_IRQ_PRIORITY_LOW,
err_code);
APP_ERROR_CHECK(err_code);
for (;;)
{
#if (SPI0_ENABLED == 1)
if (m_transfer_completed)
{
m_transfer_completed = false;
switch_state();
nrf_delay_ms(DELAY_MS);
}
#endif // (SPI0_ENABLED == 1)
}
}
I am writing the values in ADXL362 registers using following function.When I write value in particular register individually one at time and then read it back then it working.But when when I perform write operation for all register simultaneously an then read any one of them then it giving me zero value.Following is the code:
static void switch_state(void)
{
nrf_drv_spi_t const * p_instance;
nrf_drv_spi_config_t const * p_config;
switch (m_spi_master_ex_state)
{
#if (SPI0_ENABLED == 1)
case TEST_STATE_SPI0_LSB:
p_instance = &m_spi_master_0;
spi_master_init(p_instance, true);
break;
case TEST_STATE_SPI0_MSB:
p_instance = &m_spi_master_0;
spi_master_init(p_instance, false);
break;
#endif // (SPI0_ENABLED == 1)
default:
return;
}
write(p_instance, 0x25,0x03);
nrf_delay_ms(DELAY_MS);
write(p_instance, 0x23,0x58);
nrf_delay_ms(DELAY_MS);
read(p_instance, 0x23);
}
#endif // (SPI0_ENABLED == 1)
But I am facing Problem in writing the values into the ADXL362 registers using SPI_master code of nrf52. I am using UART for displaying register values on terminal.This is my main function:
int main(void)
{
// Setup bsp module.
bsp_configuration();
LEDS_CONFIGURE(LEDS_MASK);
LEDS_OFF(LEDS_MASK);
uint32_t err_code;
const app_uart_comm_params_t comm_params =
{
RX_PIN_NUMBER,
TX_PIN_NUMBER,
RTS_PIN_NUMBER,
CTS_PIN_NUMBER,
APP_UART_FLOW_CONTROL_ENABLED,
false,
UART_BAUDRATE_BAUDRATE_Baud115200
};
APP_UART_FIFO_INIT(&comm_params,
UART_RX_BUF_SIZE,
UART_TX_BUF_SIZE,
uart_error_handle,
APP_IRQ_PRIORITY_LOW,
err_code);
APP_ERROR_CHECK(err_code);
for (;;)
{
#if (SPI0_ENABLED == 1)
if (m_transfer_completed)
{
m_transfer_completed = false;
switch_state();
nrf_delay_ms(DELAY_MS);
}
#endif // (SPI0_ENABLED == 1)
}
}
I am writing the values in ADXL362 registers using following function.When I write value in particular register individually one at time and then read it back then it working.But when when I perform write operation for all register simultaneously an then read any one of them then it giving me zero value.Following is the code:
static void switch_state(void)
{
nrf_drv_spi_t const * p_instance;
nrf_drv_spi_config_t const * p_config;
switch (m_spi_master_ex_state)
{
#if (SPI0_ENABLED == 1)
case TEST_STATE_SPI0_LSB:
p_instance = &m_spi_master_0;
spi_master_init(p_instance, true);
break;
case TEST_STATE_SPI0_MSB:
p_instance = &m_spi_master_0;
spi_master_init(p_instance, false);
break;
#endif // (SPI0_ENABLED == 1)
default:
return;
}
write(p_instance, 0x25,0x03);
nrf_delay_ms(DELAY_MS);
write(p_instance, 0x23,0x58);
nrf_delay_ms(DELAY_MS);
read(p_instance, 0x23);
}
#endif // (SPI0_ENABLED == 1)