|
我在使用6-1“Heart sensor"例子上增加SPIM驱动adc,初始化有增加发送程序,初始化SPIM事件处理函数正常;
******************************************************************************/
void SPI_ADC_Init(void)
{
//配置用于SPI片选的引脚为输出
nrf_gpio_cfg_output(SPI_SS_PIN);
//拉高CS
ADC_CS_HIGH;
//使用默认配置参数初始化SPI配置结构体
nrfx_spim_config_t spi_config = NRFX_SPIM_DEFAULT_CONFIG;
//重写SPIM信号连接的引脚配置
spi_config.ss_pin = NRFX_SPIM_PIN_NOT_USED;
spi_config.miso_pin = SPI_MISO_PIN;
spi_config.mosi_pin = SPI_MOSI_PIN;
spi_config.sck_pin = SPI_SCK_PIN;
spi_config.frequency = NRF_SPIM_FREQ_8M;
//初始化SPIM
APP_ERROR_CHECK(nrfx_spim_init(&spi0, &spi_config, spi_event_handler, NULL));
spim2_xfer.p_tx_buffer = spi_tx_buf;
spim2_xfer.tx_length = 2;
spim2_xfer.p_rx_buffer = spi_rx_buf;
spim2_xfer.rx_length = 0;
//传输完成标志设置为false
spi_xfer_done = false;
ADC_CS_LOW;
APP_ERROR_CHECK(nrfx_spim_xfer(&spi0, &spim2_xfer, 0));
while(!spi_xfer_done){}
ADC_CS_HIGH;
spi_xfer_done = false;
ADC_CS_LOW;
APP_ERROR_CHECK(nrfx_spim_xfer(&spi0, &spim2_xfer, 0));
while(!spi_xfer_done){}
ADC_CS_HIGH;
}
同样的调用nrfx_spim_xfer;在心率测量定时器事件回调函数种调用读取ADC函数,无法进入SPIM事件处理函数,spi_xfer_done没办法置一;
static void heart_rate_timeout_handler(void * p_context)
{
ret_code_t err_code;
UNUSED_PARAMETER(p_context);
//心率值写死为:270bpm
heart_rate ++;
//发送心率测量值
err_code = ble_hrs_heart_rate_measurement_send(&m_hrs, heart_rate);
if ((err_code != NRF_SUCCESS) &&
(err_code != NRF_ERROR_INVALID_STATE) &&
(err_code != NRF_ERROR_RESOURCES) &&
(err_code != NRF_ERROR_BUSY) &&
(err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
)
{
APP_ERROR_HANDLER(err_code);
}
Read_MS518x_data( adc_counter );
adc_counter++;
if( adc_counter >= 255 )
{
adc_counter =0;
}
}
//读取数据也是一直的spim操作
{
ADC_CS_LOW;
APP_ERROR_CHECK(nrfx_spim_xfer(&spi0, &spim2_xfer, 0));
while(!spi_xfer_done){}
ADC_CS_HIGH;
}
|
|