spi读取的代码如下:
uint8_t spiSendByte(uint8_t byte)
{
/* Loop while DR register in not emplty */
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
/* Send byte through the SPI peripheral */
SPI_I2S_SendData(BMI088_SPI, byte);
/* Wait to receive a byte */
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
/* Return the byte read from the SPI bus */
return SPI_I2S_ReceiveData(BMI088_SPI);
}
static char spiReceiveByte()
{
return spiSendByte(0xff);
}
int spi_burst_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
{
int i;
reg_addr = (reg_addr | 0x80);
/**< Burst read code comes here */
if (dev_id == BMI088_ACCEL_I2C_ADDR_PRIMARY)
{
ACC_EN_CS();
}
else
{
GYR_DIS_CS();
GYR_EN_CS();
}
if (len SPI1_RECEIVE_BUFFER_SIZE)
{
spiSendByte(reg_addr);
for (i = 0; i < len; i++)
{
reg_data[i] = spiReceiveByte();
}
}
else
{
spiDMATransaction(reg_addr, reg_data, len);
}
if (dev_id == BMI088_ACCEL_I2C_ADDR_PRIMARY)
{
ACC_DIS_CS();
}
else
{
GYR_DIS_CS();
}
return 0;
}