Hi, I want to use a BME680 sensor and the drivers provided by Bosch, but i have to write two read and write function prototypes to communicate via SPI with the sensor. I started writing a wrapper for this driver, but i'm doing something wrong with my communication functions.
This is the function pointer prototype
* Generic communication function pointer * @param[in] dev_id: Place holder to store the id of the device structure * Can be used to store the index of the Chip select or * I2C address of the device. * @param[in] reg_addr: Used to select the register the where data needs to * be read from or written to. * @param[in/out] reg_data: Data array to read/write * @param[in] len: Length of the data array */ typedef int8_t (*bme680_com_fptr_t)(uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_t len);
The function that i wrote and does not communicate with the sensor:
static struct bme680_dev gBME680Struct = {}; static SPI_Handle gSpi; static SPI_Transaction gSpiTransaction; static uint8_t gRegAddr = 0; int8_t userTransfer(uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_t len) { if (dev_id != gBME680Struct.dev_id) { return __LINE__; } gRegAddr = reg_addr; gSpiTransaction.txBuf = (void*) &gRegAddr; gSpiTransaction.rxBuf = (void*)data; gSpiTransaction.count = len; bool success = SPI_transfer(gSpi, &gSpiTransaction); if (!success) { return __LINE__; } return 0; }
It is unclear to me what ought to be different between a write and a read function, as there is only one SPI_Transfer function. How do i send one byte and receive more? Or how do i send multiple bytes and receive no response? Would appreciate some clarifications on this issue. Thanks.