This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf51822 spi master problem

HI, I am using nrf51822 to communicate with ADT7320,using nRF51822 as the master,and the ADT7320 as the slave.I used the SPI master example,then i want to get temperature from m_rx_data_spi.But when debugging,i always get 0x00.Does that mean that i didn't configure the spi right ?I am using SDK 8.0.0.what shall i do to solve the problem?

Here is my code in main.c:

void spi_master_0_event_handler(spi_master_evt_t spi_master_evt)

{ uint32_t err_code = NRF_SUCCESS; //bool result = false;

switch (spi_master_evt.evt_type)
{
    case SPI_MASTER_EVT_TRANSFER_COMPLETED:
        // Check if received data is correct.
        //result = check_buf_equal(m_tx_data_spi, m_rx_data_spi, TX_RX_MSG_LENGTH);
        //APP_ERROR_CHECK_BOOL(result);

        // Close SPI master.
        spi_master_close(SPI_MASTER_0);

        err_code = bsp_indication_set(BSP_INDICATE_RCV_OK);
        APP_ERROR_CHECK(err_code);

        m_transfer_completed = true;
        break;

    default:
        // No implementation needed.
        break;
}

}

static void spi_master_init(spi_master_hw_instance_t spi_master_instance, spi_master_event_handler_t spi_master_event_handler, const bool lsb) { uint32_t err_code = NRF_SUCCESS;

// Configure SPI master.
spi_master_config_t spi_config = SPI_MASTER_INIT_DEFAULT;

switch (spi_master_instance)
{
    #ifdef SPI_MASTER_0_ENABLE
    case SPI_MASTER_0:
    {
        spi_config.SPI_Pin_SCK  = SPIM0_SCK_PIN;
        spi_config.SPI_Pin_MISO = SPIM0_MISO_PIN;
        spi_config.SPI_Pin_MOSI = SPIM0_MOSI_PIN;
        spi_config.SPI_Pin_SS   = SPIM0_SS_PIN;
    }
    break;
    #endif /* SPI_MASTER_0_ENABLE */

    #ifdef SPI_MASTER_1_ENABLE
    case SPI_MASTER_1:
    {
        spi_config.SPI_Pin_SCK  = SPIM1_SCK_PIN;
        spi_config.SPI_Pin_MISO = SPIM1_MISO_PIN;
        spi_config.SPI_Pin_MOSI = SPIM1_MOSI_PIN;
        spi_config.SPI_Pin_SS   = SPIM1_SS_PIN;
    }
    break;
    #endif /* SPI_MASTER_1_ENABLE */

    default:
        break;
}

spi_config.SPI_CONFIG_ORDER = (lsb ? SPI_CONFIG_ORDER_LsbFirst : SPI_CONFIG_ORDER_MsbFirst);

err_code = spi_master_open(spi_master_instance, &spi_config);
APP_ERROR_CHECK(err_code);

// Register event handler for SPI master.
spi_master_evt_handler_reg(spi_master_instance, spi_master_event_handler);

}

int main(void) {

  // Setup bsp module.
  spi_master_init(SPI_MASTER_0, spi_master_0_event_handler, false);
	
for (;; )
{     
        //switch_state(); 		      
		if (m_transfer_completed) 
    {
              m_transfer_completed = false;
              m_tx_data_spi[0] = 0x50;
	          uint32_t err_code = spi_master_send_recv(SPI_MASTER_0, m_tx_data_spi, 1, m_rx_data_spi, 2);
	          APP_ERROR_CHECK(err_code);
    }
}

}

main.c.txt

Related