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

This error message shows wrong information, fixed here
https://github.com/apache/nuttx/pull/11843

But still if this message is printed, something is wrong with the SPI data
transfer.
I don't have BMI160 around to check what the problem is, but SPI driver was
recently used by me with mrf24j40, so it should work fine.

niedz., 3 mar 2024 o 23:14 Alan C. Assis <acas...@gmail.com> napisał(a):

> 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 <maurosol...@gmail.com> 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 <nuttx/sensors/bmi160.h>
> >
> > 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
> >
> > ================= Error on NSH Terminal =================
> >
> >
> > nsh>rf52_spidev_initialize: Configure GPIO for BMI160 SPI0/CS
> > nrf52_spi_setmode: mode=0
> > nrf52_spi_setfrequency: Frequency 1000000
> > nrf52_spi0select: devid: 000d0000 CS: assert
> > nrf52_spi0select: BMI160 device asserted
> > nrf52_spi_exchange: Incomplete transfer wrote 536915151 expected 1
> > nrf52_spi0select: devid: 000d0000 CS: de-assert
> > nrf52_spi0select: BMI160 device de-asserted
> > nrf52_spi_setmode: mode=0
> > nrf52_spi0select: devid: 000d0000 CS: assert
> > nrf52_spi0select: BMI160 device asserted
> > nrf52_spi_exchange: Incomplete transfer wrote 536915151 expected 1
> > nrf52_spi0select: devid: 000d0000 CS: de-assert
> > nrf52_spi0select: BMI160 device de-asserted
> > nrf52_spi_setmode: mode=0
> > nrf52_spi0select: devid: 000d0000 CS: assert
> > nrf52_spi0select: BMI160 device asserted
> > nrf52_spi_exchange: Incomplete transfer wrote 536915143 expected 1
> > nrf52_spi0select: devid: 000d0000 CS: de-assert
> > nrf52_spi0select: BMI160 device de-asserted
> > ERROR: bmi160_register failed: -19
> >
> > Em seg., 26 de fev. de 2024 às 03:57, raiden00pl <raiden0...@gmail.com>
> > escreveu:
> >
> > > You need to specify that SPI is used as master:
> > CONFIG_NRF52_SPI0_MASTER=y
> > >
> > > niedz., 25 lut 2024 o 21:22 Mauro Sollar <maurosol...@gmail.com>
> > > napisał(a):
> > >
> > > > Hi,
> > > >
> > > > I'm trying to use the BMI160 sensor with the Nordic nRF52832-dk Kit,
> > help
> > > > me please!
> > > >
> > > > Kconfig Configuration:
> > > >
> > > > System type
> > > >   nRF52 Peripheral Selection
> > > >     (*) SPI 0
> > > > Device Drivers
> > > >   (*) SPI Driver Support
> > > >     (*) SPI character driver
> > > >   (*) Sensor Device Support
> > > >     (*) Bosch BMI160 Inertial Measurement Sensor support
> > > >   IO Expander/GPIO Support
> > > >     (*) GPIO driver
> > > > Application Configuration
> > > >   Examples
> > > >     (*) BMI160
> > > >
> > > > I added the following lines to the file:
> > > > ./boards/arm/nrf52/nrf52832-dk/src/nrf52_bringup.c
> > > >
> > > >
> > > > int nrf52_bringup(void)
> > > > {
> > > >   int ret;
> > > > ...
> > > > ...
> > > > ...
> > > >
> > > >   struct spi_dev_s *dev = nrf52_spibus_initialize(0);
> > > >   ret = bmi160_register("/dev/accel0", dev);
> > > >   if (ret < 0)
> > > >     {
> > > >       syslog(LOG_ERR, "ERROR: bmi160_register failed: %d\n", ret);
> > > >     }
> > > >
> > > > ...
> > > > ...
> > > > ...
> > > >
> > > >
> > > > }
> > > >
> > > > Show this error:
> > > >
> > > > board/nrf52_bringup.c:104:27: warning: implicit declaration of
> function
> > > > 'nrf52_spibus_initialize'; did you mean 'nrf52_spidev_initialize'?
> > > > [-Wimplicit-function-declaration]
> > > >   104 |   struct spi_dev_s *dev = nrf52_spibus_initialize(0);
> > > >       |                           ^~~~~~~~~~~~~~~~~~~~~~~
> > > >       |                           nrf52_spidev_initialize
> > > > board/nrf52_bringup.c:104:27: warning: initialization of 'struct
> > > spi_dev_s
> > > > *' from 'int' makes pointer from integer without a cast
> > > [-Wint-conversion]
> > > > LD: nuttx
> > > > arm-none-eabi-ld:
> > > > /home/mauro/nuttxspace/nuttx/staging/libdrivers.a(bmi160_base.o): in
> > > > function `bmi160_getreg8':
> > > > /home/mauro/nuttxspace/nuttx/drivers/sensors/bmi160_base.c:87:
> > undefined
> > > > reference to `bmi160_configspi'
> > > > arm-none-eabi-ld:
> > > > /home/mauro/nuttxspace/nuttx/staging/libdrivers.a(bmi160_base.o): in
> > > > function `bmi160_putreg8':
> > > > /home/mauro/nuttxspace/nuttx/drivers/sensors/bmi160_base.c:145:
> > undefined
> > > > reference to `bmi160_configspi'
> > > > arm-none-eabi-ld:
> > > > /home/mauro/nuttxspace/nuttx/staging/libdrivers.a(bmi160_base.o): in
> > > > function `bmi160_getreg16':
> > > > /home/mauro/nuttxspace/nuttx/drivers/sensors/bmi160_base.c:205:
> > undefined
> > > > reference to `bmi160_configspi'
> > > > arm-none-eabi-ld:
> > > > /home/mauro/nuttxspace/nuttx/staging/libdrivers.a(bmi160_base.o): in
> > > > function `bmi160_getregs':
> > > > /home/mauro/nuttxspace/nuttx/drivers/sensors/bmi160_base.c:265:
> > undefined
> > > > reference to `bmi160_configspi'
> > > > make[1]: *** [Makefile:197: nuttx] Erro 1
> > > > make: *** [tools/Unix.mk:546: nuttx] Erro 2
> > > >
> > > >
> > > > thanks,
> > > > --
> > > > Mauro Costa Sollar
> > > > Cel.: 31 98894-2932
> > > >
> > >
> >
> >
> > --
> > Mauro Costa Sollar
> > Cel.: 31 98894-2932
> >
>

Reply via email to