Re: BMI160 on Nordic nRF52832-dk Kit

2024-03-03 Thread Alan C. Assis
Hi Mauro,

I think there is some issue in your SPI (I don't know if it is in your
configuration, or on your wiring, or in our device, or something else).

The issue you are seeing (only 1 bit transmitted) could be confirmed by
this error message:

nrf52_spi_exchange: Incomplete transfer wrote 536915151 expected 1

Looking at your configuration I noticed you enabled the char driver
support, but it is not required for native SPI drivers, it is used only for
testing.

(*) SPI character driver

It will create a /dev/spi0 that could be used to test SPI communication
directly, but since you are not using SPI test application, I think it is
not necessary.

I also noticed that 536915151 is 0x2000ACCF, which seems like a memory
pointer, which raises my suspicion there is some misconfiguration issue.

There are only two boards that currently have support for this sensor and
they used I2C.

So, I suggest you test first using I2C, since you can use a board as
reference. Or maybe someone working with this chip could help (not sure if
Raiden00 has this chip).

BR,

Alan

On Sun, Mar 3, 2024 at 6:08 PM Mauro Sollar  wrote:

> Hi,
>
> I made the recommended change and it compiled normally, but I saw that the
> code was missing the implementation of the CS signal, so I made the changes
> below and it still didn't work. Does the code really work for the
> nRF52832-DK? I used my logic analyzer and there is no information on the
> data line, only 1 in the 8 bits, but there is the rise and fall of the
> signal, I also checked the clock and it is ok! This is very confusing for
> me, I thought it would be easier to use the example of this BMI160 sensor.
> If you have any further help I would appreciate it again! Thanks!
>
> == vi
> ./boards/arm/nrf52/nrf52832-dk/src/nrf52_bringup.c
>
> #include "nrf52_spi.h"
> #include 
>
> int nrf52_bringup(void)
> {
>   int ret;
> ...
> ...
> ...
>
>   struct spi_dev_s *dev = nrf52_spibus_initialize(0);
>   <<<--- Added by me
>   ret = bmi160_register("/dev/accel0", dev);
>  <<<---
>   if (ret < 0)
>  <<<---
> {
>  <<<---
>   syslog(LOG_ERR, "ERROR: bmi160_register failed: %d\n", ret);
> <<<---
> }
>  <<<---
>
> ...
> ...
> ...
>
>
> }
>
>
> == vi
> ./boards/arm/nrf52/nrf52832-dk/include/board.h
>
> #define BOARD_SPI0_CS_PIN  (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 |
> GPIO_PIN(11))<<<--- Added by me
> #define BOARD_SPI0_INT_PIN (GPIO_OUTPUT | GPIO_PORT0 | GPIO_PIN(12))
><<<---
>
> vi ./arch/arm/src/board/board/nrf52832-dk.h e adicione as linhas abaixo:
>
> /* BMI160 pins
>  * CS   - P0.11
>  * INT  - P0.12
>  */
>
> #define GPIO_BMI160_CS(GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 |
> GPIO_PIN(11))   <<<--- Added by me
> #define GPIO_BMI160_INT   (GPIO_INPUT  | GPIO_PORT0 | GPIO_PIN(12))
>  <<<---
>
>
> == vi
> ./boards/arm/nrf52/nrf52832-dk/src/nrf52_spi.c
>
>
> void nrf52_spidev_initialize(void)
> {
> #ifdef CONFIG_NRF52_SPI0_MASTER
> #  ifdef CONFIG_IEEE802154_MRF24J40
>   /* Configure the SPI-based MRF24J40 chip select GPIO */
>
>   spiinfo("Configure GPIO for MRF24J40 SPI1/CS\n");
>
>   nrf52_gpio_config(GPIO_MRF24J40_CS);
>   nrf52_gpio_write(GPIO_MRF24J40_CS, true);
> #  endif
> #  ifdef CONFIG_SENSORS_BMI160
> <<<--- Added by me
>   /* Configure the SPI-based BMI160 chip select GPIO */  <<<---
>
>   spiinfo("Configure GPIO for BMI160 SPI0/CS\n");<<<---
>
>   nrf52_gpio_config(GPIO_BMI160_CS); <<<---
>   nrf52_gpio_write(GPIO_BMI160_CS, true);<<<---
> #  endif
><<<---
> #endif
> }
>
> ifdef CONFIG_NRF52_SPI0_MASTER
> void nrf52_spi0select(struct spi_dev_s *dev, uint32_t devid,
>   bool selected)
> {
>   spiinfo("devid: %08lx CS: %s\n",
>   (unsigned long)devid, selected ? "assert" : "de-assert");
>
>   spiinfo("BMI160 device %s\n",<<<---
> Added by me
>   selected ? "asserted" : "de-asserted");  <<<---
>   /* Set the GPIO low to select and high to de-select */   <<<---
>   nrf52_gpio_write(GPIO_BMI160_CS, !selected); <<<---
>
>   switch (devid)
> {
> #ifdef CONFIG_IEEE802154_MRF24J40
> case SPIDEV_IEEE802154(0):
> {
>   spiinfo("MRF24J40 device %s\n",
>   selected ? "asserted" : "de-asserted");
>
>   /* Set the GPIO low to select and high to de-select */
>
>   nrf52_gpio_write(GPIO_MRF24J40_CS, !selected);
>   break;
> }
> #endif
>
>   default:
> {
>   break;
> }
> }
> }
>
> uint8_t nr

Re: BMI160 on Nordic nRF52832-dk Kit

2024-03-03 Thread Mauro Sollar
Hi,

I made the recommended change and it compiled normally, but I saw that the
code was missing the implementation of the CS signal, so I made the changes
below and it still didn't work. Does the code really work for the
nRF52832-DK? I used my logic analyzer and there is no information on the
data line, only 1 in the 8 bits, but there is the rise and fall of the
signal, I also checked the clock and it is ok! This is very confusing for
me, I thought it would be easier to use the example of this BMI160 sensor.
If you have any further help I would appreciate it again! Thanks!

== vi
./boards/arm/nrf52/nrf52832-dk/src/nrf52_bringup.c

#include "nrf52_spi.h"
#include 

int nrf52_bringup(void)
{
  int ret;
...
...
...

  struct spi_dev_s *dev = nrf52_spibus_initialize(0);
  <<<--- Added by me
  ret = bmi160_register("/dev/accel0", dev);
 <<<---
  if (ret < 0)
 <<<---
{
 <<<---
  syslog(LOG_ERR, "ERROR: bmi160_register failed: %d\n", ret);
<<<---
}
 <<<---

...
...
...


}


== vi
./boards/arm/nrf52/nrf52832-dk/include/board.h

#define BOARD_SPI0_CS_PIN  (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 |
GPIO_PIN(11))<<<--- Added by me
#define BOARD_SPI0_INT_PIN (GPIO_OUTPUT | GPIO_PORT0 | GPIO_PIN(12))
   <<<---

vi ./arch/arm/src/board/board/nrf52832-dk.h e adicione as linhas abaixo:

/* BMI160 pins
 * CS   - P0.11
 * INT  - P0.12
 */

#define GPIO_BMI160_CS(GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 |
GPIO_PIN(11))   <<<--- Added by me
#define GPIO_BMI160_INT   (GPIO_INPUT  | GPIO_PORT0 | GPIO_PIN(12))
 <<<---


== vi
./boards/arm/nrf52/nrf52832-dk/src/nrf52_spi.c


void nrf52_spidev_initialize(void)
{
#ifdef CONFIG_NRF52_SPI0_MASTER
#  ifdef CONFIG_IEEE802154_MRF24J40
  /* Configure the SPI-based MRF24J40 chip select GPIO */

  spiinfo("Configure GPIO for MRF24J40 SPI1/CS\n");

  nrf52_gpio_config(GPIO_MRF24J40_CS);
  nrf52_gpio_write(GPIO_MRF24J40_CS, true);
#  endif
#  ifdef CONFIG_SENSORS_BMI160
<<<--- Added by me
  /* Configure the SPI-based BMI160 chip select GPIO */  <<<---

  spiinfo("Configure GPIO for BMI160 SPI0/CS\n");<<<---

  nrf52_gpio_config(GPIO_BMI160_CS); <<<---
  nrf52_gpio_write(GPIO_BMI160_CS, true);<<<---
#  endif
   <<<---
#endif
}

ifdef CONFIG_NRF52_SPI0_MASTER
void nrf52_spi0select(struct spi_dev_s *dev, uint32_t devid,
  bool selected)
{
  spiinfo("devid: %08lx CS: %s\n",
  (unsigned long)devid, selected ? "assert" : "de-assert");

  spiinfo("BMI160 device %s\n",<<<---
Added by me
  selected ? "asserted" : "de-asserted");  <<<---
  /* Set the GPIO low to select and high to de-select */   <<<---
  nrf52_gpio_write(GPIO_BMI160_CS, !selected); <<<---

  switch (devid)
{
#ifdef CONFIG_IEEE802154_MRF24J40
case SPIDEV_IEEE802154(0):
{
  spiinfo("MRF24J40 device %s\n",
  selected ? "asserted" : "de-asserted");

  /* Set the GPIO low to select and high to de-select */

  nrf52_gpio_write(GPIO_MRF24J40_CS, !selected);
  break;
}
#endif

  default:
{
  break;
}
}
}

uint8_t nrf52_spi0status(struct spi_dev_s *dev, uint32_t devid)
{
  uint8_t status = 0;

  status |= SPI_STATUS_PRESENT; <<- Added by me

  switch (devid)
{
#ifdef CONFIG_IEEE802154_MRF24J40
  case SPIDEV_IEEE802154(0):
{
  status |= SPI_STATUS_PRESENT;
  break;
}
#endif

  default:
{
  break;
}
}

  return status;
}



== vi ./arch/arm/src/nrf52/nrf52_spi.c

static void nrf52_spi_gpioinit(struct nrf52_spidev_s *priv)
{
  nrf52_gpio_config(priv->sck_pin);
  nrf52_spi_pselinit(priv, NRF52_SPIM_PSELSCK_OFFSET, priv->sck_pin);

#ifdef CONFIG_NRF52_SPI0_MASTER
  if (priv == &g_spi0dev)
{
  nrf52_gpio_config(BOARD_SPI0_CS_PIN);  <<<---
Added by me
  nrf52_spi_pselinit(priv, NRF52_SPIM_PSELCSN_OFFSET,<<<---
 BOARD_SPI0_CS_PIN);

#ifdef BOARD_SPI0_MISO_PIN
  nrf52_gpio_config(BOARD_SPI0_MISO_PIN);
  nrf52_spi_pselinit(priv, NRF52_SPIM_PSELMISO_OFFSET,
 BOARD_SPI0_MISO_PIN);
#endif
#ifdef BOARD_SPI0_MOSI_PIN
  nrf52_gpio_config(BOARD_SPI0_MOSI_PIN);
  nrf52_spi_pselinit(priv, NRF52_SPIM_PSELMOSI_OFFSET,
 BOARD_SPI0_MOSI_PIN);
  nrf52_gpio_write(BOARD_SPI0_MOSI_PIN, false);
#endif
}
#endif

=