Hi Nordic team,
I'm using an accelerometer ( FXLS8964AF from NXP) and the evaluation board nrf9160dk as master but I can't communicate them.
My code:
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/spi.h>
#define MY_SPI_MASTER DT_NODELABEL(my_spi_master)
// SPI master functionality
const struct device* _gSpiDev = DEVICE_DT_GET(MY_SPI_MASTER);
struct spi_cs_control spim_cs = {
.gpio = SPI_CS_GPIOS_DT_SPEC_GET(DT_NODELABEL(reg_my_spi_master)),
.delay = 0,
};
static const struct spi_config _gSpiCfg = {
.operation = SPI_WORD_SET(8) |
SPI_TRANSFER_MSB |
SPI_MODE_CPOL |
SPI_MODE_CPHA |
SPI_OP_MODE_MASTER,
.frequency = 1000000,
.slave = 0,
.cs = &spim_cs,
};
int main(void)
{
while(1){
if (!device_is_ready(_gSpiDev)) {
while(1);
}
if(!device_is_ready(spim_cs.gpio.port)){
while(1);
}
int ret;
uint8_t txBuf[2] = {0x80 | 0x13, 0x00}; // Read who am i register
uint8_t rxBuf[2];
const struct spi_buf txSpiBuf = {
.buf = txBuf,
.len = sizeof(txBuf),
};
const struct spi_buf_set txSpiBufSet = {
.buffers = &txSpiBuf,
.count = 1,
};
struct spi_buf rxSpiBuf = {
.buf = rxBuf,
.len = sizeof(rxBuf),
};
const struct spi_buf_set rxSpiBufSet = {
.buffers = &rxSpiBuf,
.count = 1,
};
ret = spi_transceive(_gSpiDev, &_gSpiCfg, &txSpiBufSet,&rxSpiBufSet);
if (ret < 0) {
while(1);
return 0;
}
txBuf[0] = (0x00 | 0x13); //Write test
txBuf[1] = 0x00;
ret = spi_transceive(_gSpiDev, &_gSpiCfg, &txSpiBufSet,&rxSpiBufSet);
if (ret < 0) {
while(1);
return 0;
}
return 0;
}
Overlay file:
Do you have any idea how I can solve this issue?
Please find attached pictures for "writing" and "reading" modes.
writing
reading
Thank you in advance.
Best regards,
Tania