I use SPI to develop motion sensors KX022 and DW1000. The first digit of the received data is always 0xFF. If the first byte received is removed, it can be used normally. I want to know what caused this.
The results are the same with or without EasyDMA.
Look forward to your reply, thank you.
void spi_kx022_init(void)
{
ret_code_t err_code;
//使用默认配置参数初始化SPI配置结构体
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
//重写SPI信号连接的引脚配置
spi_config.ss_pin = NRF_DRV_SPI_PIN_NOT_USED;
spi_config.miso_pin = KX022_PIN_SDO;
spi_config.mosi_pin = KX022_PIN_SDI;
spi_config.sck_pin = KX022_PIN_SCL;
spi_config.mode = NRF_DRV_SPI_MODE_3;
//初始化SPI,应用程序的事件句柄是NULL,SPI工作于阻塞模式
APP_ERROR_CHECK(nrf_drv_spi_init(&kx022_spi, &spi_config, NULL, NULL));
nrf_gpio_cfg_output(KX022_PIN_CS);
nrf_gpio_pin_set(KX022_PIN_CS);
if (!nrf_drv_gpiote_is_init())
{
err_code = nrf_drv_gpiote_init();
APP_ERROR_CHECK(err_code);
}
// pin config interrupt
nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_LOTOHI(false);
in_config.pull = NRF_GPIO_PIN_PULLDOWN;
err_code = nrf_drv_gpiote_in_init(KX022_PIN_INT1, &in_config, kx022_pin_int1_handler);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_event_enable(KX022_PIN_INT1, true);
kx022_init();
}
static void bsp_kx022_spi_write(uint8_t Reg_Addr,uint8_t Reg_Data)
{
spi_tx_buf[0] = (Reg_Addr & (~KX022_READ));
spi_tx_buf[1] = Reg_Data;
KX022_CS_ENABLE();
APP_ERROR_CHECK(nrf_drv_spi_transfer(&kx022_spi, spi_tx_buf, 2, spi_rx_buf, 0));
KX022_CS_DISABLE();
}
static uint8_t bsp_kx022_spi_read(uint8_t Reg_Addr)
{
spi_tx_buf[0] = (Reg_Addr | KX022_READ);
spi_tx_buf[1] = 0x00;
KX022_CS_ENABLE();
APP_ERROR_CHECK(nrf_drv_spi_transfer(&kx022_spi, spi_tx_buf, 2, spi_rx_buf, 2));
KX022_CS_DISABLE();
return spi_rx_buf[1];
}