Connect Metaware C Pro to NRF51-DK dev board to reprogram bootloader and flash

I
know that you do not support firmware development but you do give instructions
on how to flash your own firmware to the board. My problem is that I am trying
to flash a c pro using the NRF51 DK as recommended on your site (https://mbientlab.com/firmware/). The
description of the connections for this combination of boards is vague.

 I
have (some are guesses as not detailed in guide on website)

 

C pro
pin 5 Vgnd <-> dk gnd pin

C pro
pin 6 V3v <-> dk P20 pin 1

C pro
pin 11 V3v <-> dk p20 pin 3

C pro
pin 12 Vgnd <-> dk p20 pin 8

C pro
pin 13 SWDIO/nReset <-> dk p20 pin 4

C pro
pin 14 SWDCLK <-> dk p20 pin 5

 

This
is obviously incorrect. The nrf51 dk board knows that there is an external
board present but cannot connect to it and I have tried a large variety of
tools and combinations to connect.

Comments

  • @jhurley

    Simply attach a debug header to the MetaWearC, and connect it to the "Debug Out" connector on the nRF51 DK with a 10 pin cable as shown here:
    image

    You will need to have the battery in the device and the DK should pick it up.  Make sure that you are using the JLink firmware on the DK, and that the JLink is configured in SWD/SW mode -- JTAG mode does not work with the nRF51.

    In order to get any firmware to boot past the softdevice init, you will need to make sure the device is configured for the 32Mhz crystal in the Taiyo module.  There are multiple ways listed for how to achieve this in the MetaWearC datasheet.

    Cheers
  • Thanks that worked. I don't suppose you have the datasheet for the BMI160 handy. The SPI settings for it is what I am really after.
  • edited February 2016
    BMI160 spec sheet is on the Bosch website, under the "Documents & Drivers" tab.

  • Thanks.
    When I googled that yesterday and clicked on what looks like the same link I got a site down error, must just have been unlucky.


  • I am still struggling with the BMI160 spi interface.
    My RX registers are always 0xFF.
    I have 

    #define SPI0_ENABLED 1

    #if (SPI0_ENABLED == 1)
    #define SPI0_USE_EASY_DMA 0

    #define SPI0_CONFIG_SCK_PIN         30
    #define SPI0_CONFIG_MOSI_PIN         7
    #define SPI0_CONFIG_MISO_PIN         0
    #define SPI0_CONFIG_IRQ_PRIORITY    APP_IRQ_PRIORITY_LOW

    #define SPI0_INSTANCE_INDEX 0

    in a config file.

    #define SPI_CS_PIN 11
    #define SPI_BUFFER_SIZE 16

    #define SPI_INSTANCE  0
    static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);  
    static volatile bool spi_xfer_done;  

    static uint8_t       m_tx_buf[SPI_BUFFER_SIZE];           
    static uint8_t       m_rx_buf[SPI_BUFFER_SIZE];    
    static const uint8_t m_length = SPI_BUFFER_SIZE;        

    as global variables.

    I have an init function 
    void spi_master_init(void)
    {
        nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG(SPI_INSTANCE);
    spi_config.ss_pin = SPI_CS_PIN;
        spi_config.frequency = NRF_DRV_SPI_FREQ_8M;
       spi_config.mode = NRF_DRV_SPI_MODE_1;
        APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler));
    m_tx_buf[0] = 0X80;
    }


  • cont



    and a write function that looks like:
            memset(m_rx_buf, 0, SPI_BUFFER_SIZE);
            spi_xfer_done   = false;

        APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, m_tx_buf, 8, m_rx_buf, 8));

            while(spi_xfer_done == false)
            {
                __SEV();
                __WFE();
                __WFE();
            }

    the spi_event_handler is calling and the tx reg is as setup but the rx reg is always 0XFF regardless of what value I send.

    Any ideas?
  • @jhurley : Pin definitions look good.  The only thing that seems out of place is the SPI_MODE -- We are using mode 3 compared to your mode 1.  If that does not help, I would trace through the code to make sure all of the pins are configured into the proper input or output modes -- getting only 0xFF it is likely that the input is not being received or the clock is not actually driving the pin.
  • Hi Matt,

    Sorry I meant to post back here. I managed to get it working. There were 3 issues:

    1) The mode (I am now using 0 but the datasheet suggests that 3 would also work)
    2) I had the wrong dma mode.
    3) I was not reading back enough bytes. (This one was a fairly stupid one I will admitt)

    Thanks for all the help.
  • Hi,
    I'm trying to work with BMI160 over SPI ( RG board ).

    On nrf_drv_config.h:

    /* SPI */
    #define SPI0_ENABLED 1

    #if (SPI0_ENABLED == 1)
    #define SPI0_USE_EASY_DMA 0

    #define SPI0_CONFIG_SCK_PIN         0
    #define SPI0_CONFIG_MOSI_PIN        7
    #define SPI0_CONFIG_MISO_PIN        11
    #define SPI0_CONFIG_IRQ_PRIORITY    APP_IRQ_PRIORITY_LOW

    #define SPI0_INSTANCE_INDEX 0
    #endif

    On main.c:

    #define SPI_CS_PIN 10
    #define SPI_BUFFER_SIZE 16

    #define SPI_INSTANCE  0
    static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);  
    static volatile bool spi_xfer_done;  

    static uint8_t       m_tx_buf[SPI_BUFFER_SIZE];           
    static uint8_t       m_rx_buf[SPI_BUFFER_SIZE];    
    static const uint8_t m_length = SPI_BUFFER_SIZE;       


    void spi_event_handler(nrf_drv_spi_evt_t const * p_event)
    {
        spi_xfer_done = true;
    }
    void spi_master_init(void)
    {
          nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG(SPI_INSTANCE);
          spi_config.ss_pin            = SPI_CS_PIN;
          spi_config.miso_pin          = SPI0_CONFIG_MISO_PIN;
          spi_config.mosi_pin          = SPI0_CONFIG_MOSI_PIN;
          spi_config.sck_pin           = SPI0_CONFIG_SCK_PIN;
          spi_config.frequency         = NRF_DRV_SPI_FREQ_1M;
          spi_config.mode                 = NRF_DRV_SPI_MODE_3;
          spi_config.irq_priority = SPI0_CONFIG_IRQ_PRIORITY;
          APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler));
    }

    On main routine:

                    m_tx_buf[0] = 0x00  |  0x80 ;  // chip id reg adr | read_mask
                    memset(m_rx_buf, 0, SPI_BUFFER_SIZE);
                    spi_xfer_done   = false;
                    APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, m_tx_buf, 1, m_rx_buf, 1));
                    while(spi_xfer_done == false){;}       
                   
    After the while loop for spi_xfer_done m_rx_buf[0] is always 0xFF;

    The main problem is that I can't use oscilloscope ( no test/pad pin on specifications ).
    So, I can't understand what happen (debugging step by step seems good).

    I tried to swap MISO and MOSI pin cause pdf spacifications is not so clear.
    Other strange thing is that in specification pdf there is a draw with i2c BMI160 connection ( Figure 1 Block diagram ) but the "Internal Module Pin list" says that BMI160 is connected via SPI.

    Thank you for any answer.

  • I tried to use spi pins directly by a simple software routine (always usefull for try to understand).
    So, I was using in wrong way the function nrf_drv_spi_transfer. The lengh of buffers was 1, not enought for 16bit clock cycle.
    Jhurley had the solution and I didn't see: "I was not reading back enough bytes".
    Thank you for reading.
  • I realize this is not a good place for this, but would anyone be willing to look over some code and see if you find the problem? We are working on testing SPI and keep getting the 0xFF returns instead of actual values. We've tried everything mentioned here and then some to no avail.
  • I tried that I would realize the SPI interface for BMI160 according to the above mentioned methods, but I couldn't get the correct results. SPI values from BMI160 always was 0xFF.
  • Are you guys using CPRO boards?
  • OK, so do you have the pins correctly set?

    Assuming they are correctly defined in your code, what does your bmi160 init code look like? Also, what exactly have you tried thus far?
  • This is a beast because we decalred a lot of stuff explicitly instead of keeping it in library files.


    We have ensured pin assignments, run the SPI loopback successfully, changed the buffer size from 1 to 2, set DMA - all with no change.
This discussion has been closed.