Hi team,
I want to make simple communication between NRF52840 dongle and mcp2517 CAN FD contoller using SPI. I do not understand, how to send and read values to and from registers. Same SPI communication works well between dongles.
I set the register value
// Defined register values for MCP #define cINSTRUCTION_WRITE 0x02
Set the SPI instance index and flag
/**< SPI instance index. */ static const nrfx_spim_t spi = NRFX_SPIM_INSTANCE(SPI_INSTANCE); /**< SPI instance. */ /**< Flag used to indicate that SPI instance completed the transfer. */ static volatile bool spi_xfer_done;
Created two buffers for transfer and receive and set transfer length
static uint8_t m_tx_buf[5]; //static uint8_t cINSTRUCTION_WRITE_m_rx_buf[5]; /**< RX buffer. */ static uint8_t m_rx_buf[5]; /**< RX buffer. */ static const uint8_t m_length = sizeof(m_tx_buf); /**< Transfer length. */
SPIM event handler function
void spim_event_handler(nrfx_spim_evt_t const * p_event,
void * p_context)
{
spi_xfer_done = true;
/*
NRF_LOG_INFO("Transfer completed.");
if (m_rx_buf[0] != 0)
{
NRF_LOG_INFO(" Received:");
NRF_LOG_HEXDUMP_INFO(m_rx_buf, strlen((const char *)m_rx_buf));
}
*/
}
In the main function I set function for starting the SPI data transfer with DCX control with SPI config
nrfx_spim_xfer_desc_t xfer_desc = NRFX_SPIM_XFER_TRX(m_tx_buf, m_length, m_rx_buf, m_length);
nrfx_spim_config_t spi_config = NRFX_SPIM_DEFAULT_CONFIG;
spi_config.frequency = NRF_SPIM_FREQ_1M;
spi_config.ss_pin = NRFX_SPIM_SS_PIN;
spi_config.miso_pin = NRFX_SPIM_MISO_PIN;
spi_config.mosi_pin = NRFX_SPIM_MOSI_PIN;
spi_config.sck_pin = NRFX_SPIM_SCK_PIN;
spi_config.dcx_pin = NRFX_SPIM_DCX_PIN;
spi_config.use_hw_ss = true;
spi_config.ss_active_high = false;
APP_ERROR_CHECK(nrfx_spim_init(&spi, &spi_config, spim_event_handler, NULL));
And in the while loop I should start writing and reading registers. Here I start to face with the problems. How I can prepare tx_buf with values and how to start send values and read it from register?
Sorry about huge misunderstanding, but I need to make things clear.