Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SPI example: MOD BLOCK Register Adress

Hey guys,

I'm working with a Laird BL652-DVK (nrF 52832 - Chip) and Nordic SDK v.14.2.0. Now I try the SPI example and I don't know which register is adressed in the last line? I can't find it in LIS3DH-Datasheet (accelerometer).

"

//MOD BLOCK FOR NEW REG

static uint8_t       m_config_buf1[] = {0x20,0x97};   //CTRL_REG1: 9 = normal power mode (1.344kHz), Low-power Mode (5.376kHz); 7 = Z-,Y-,X-axis enable


static uint8_t       m_config_buf2[] = {0x23,0x88};   //CTRL_REG4: 8 = output registers not updated until MSB and LSB reading; 8 = high-resolution output mode enabled


static uint8_t       m_config_buf3[] = {0x22,0x10};   //CTRL_REG3: 1 = ZYXDA interrupt on INT1 enable


static uint8_t       m_config_buf4[] = {0x1F,0x80};   //TEMP_CFG_REG: 8 = ADC enabled


static uint8_t       m_config_buf5[] = {0x23,0x88};   //CTRL_REG4: 8 = output registers not updated until MSB and LSB reading; 8 = high-resolution output mode enabled


static uint8_t       m_config_buf6[] = {0xA3,0x00};  //???

"

Thanks in advance,

Christoph

Parents
  • Hi Christoph,

    Is this code from a Nordic SDK? I searched through SDK 14.2.0 but couldn't find it. Also, it looks like only a few of the registers above actually match the datasheet. E.g., the address to CTRL_REG2 is 0x21 in the datasheet, but 0x23 in the code.

    Best regards,

    Vidar

  • Hey Vidar,

    Yes it's from the SPI example (.../examples/peripheral/spi). The whole code is below.

    /*Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
     * 
     * All rights reserved.
     * 
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     * 
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     * 
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     * 
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     * 
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     * 
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     * 
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     * 
     */
    #include <nrf_drv_spi.h>
    #include "app_util_platform.h"
    #include "nrf_gpio.h"
    #include "nrf_delay.h"
    #include "boards.h"
    #include "app_error.h"
    #include <string.h>
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    #include <stdint.h>
    #include <stdbool.h>
    
    #define SPI_INSTANCE  0 /**< SPI instance index. */
    static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);  /**< SPI instance. */
    static volatile bool spi_xfer_done = false;  /**< Flag used to indicate that SPI instance completed the transfer. */
    
    //MOD BLOCK FOR NEW REG
    
    static uint8_t       m_config_buf1[] = {0x20,0x97};
    static uint8_t       m_config_buf2[] = {0x23,0x88};
    static uint8_t       m_config_buf3[] = {0x22,0x10};
    static uint8_t       m_config_buf4[] = {0x1F,0x80};
    static uint8_t       m_config_buf5[] = {0x23,0x88};
    static uint8_t       m_config_buf6[] = {0xA3,0x00};
    
    uint8_t read_data[7];
    
    static uint8_t		 m_get_buf1[] = {0xE8,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA};
    
    
    
    void config_accel(){
    
        nrf_drv_spi_transfer(&spi, m_config_buf1, sizeof(m_config_buf1), NULL, 0);
        nrf_delay_us(160);
        nrf_drv_spi_transfer(&spi, m_config_buf2, sizeof(m_config_buf2), NULL, 0);
        nrf_delay_us(160);
        nrf_drv_spi_transfer(&spi, m_config_buf3, sizeof(m_config_buf3), NULL, 0);
        nrf_delay_us(160);
    	nrf_drv_spi_transfer(&spi, m_config_buf4, sizeof(m_config_buf4), NULL, 0);
        nrf_delay_us(160);
        nrf_drv_spi_transfer(&spi, m_config_buf5, sizeof(m_config_buf5), NULL, 0);
        nrf_delay_us(160);
        nrf_drv_spi_transfer(&spi, m_config_buf6, sizeof(m_config_buf6), NULL, 0);
        nrf_delay_ms(1000);
    
    }
    
    void get_accel(){
    	while (1){
    				nrf_drv_spi_transfer(&spi, m_get_buf1, sizeof(m_get_buf1), read_data, sizeof(read_data));
    	    		nrf_delay_ms(20);
    	        }
    }
    
    void spi_event_handler(nrf_drv_spi_evt_t const * p_event,
                           void *                    p_context)
    {
        spi_xfer_done = true;
    }
    
    int main(void)
    {
    
        nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
        spi_config.ss_pin   = 22;
        spi_config.miso_pin = 24;
        spi_config.mosi_pin = 23;
        spi_config.sck_pin  = 25;
    	spi_config.frequency = NRF_DRV_SPI_FREQ_2M;
        spi_config.mode     = NRF_DRV_SPI_MODE_3;
        nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL);
    
    	config_accel();
    
    	get_accel();
    }
    

    I just see that there is nothing in the description of an acceleration sensor or that an acceleration sensor should be adressed. Do you know which sensor is adressesd / should be adressed with the SPI example? (I want to address an accelerometer.)

    And you are right, some adresses are missing. I think that these addresses will not be changed and should remain set to default.

    Best regards,

    Christoph

  • Hi Christoph,

    I'm confused, the code you posted is not from the original SDK example. Did you define the m_config_buf[] arrays yourself or is it from a third party? 

  • Hi Vidar,

    apologize, you are right. I got the project from a colleaguq without a note or explanation. So I assumed that the SPI example was not modified. But after you wrote that you can not find my code, I started to ponder and I downloaded the SDK v.14.2.0 again and looked it up in main.c. The result: my SPI example was modfied by my colleague. I'm sorry and thank you for your help.

    I wish you a nice thursday and Merry Christmas.

    Christoph

  • Hi Christoph,

    No worries. That explains everything, thanks for the update. And Merry Christmas to you.

    Vidar

Reply Children
Related