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

Connecting nRF52840 DK to MC3672 Accelerometer

Hi, 

I'm new to building circuits with Nordic devices and am unsure about how to connect the MC3672 accelerometer: https://mcubemems.com/wp-content/uploads/2020/03/EV3672AB-Quick-Start-Guide-and-Demo-APS-045-0017v1.5.pdf to the nRF52840 DK via I2C/SPI. I'd like to read the accelerometer values on my Mac via BLE.

I'd appreciate guidance on which pins to use to connect my accelerometer to the DK board. I've looked through the documentation which states that you can choose your own pins for the I2C/SPI interface but it doesn't explain how to do so in a very beginner-friendly way.

I'd also appreciate if someone would kindly point me in the direction of some example code that reads external sensor values using I2C/SPI connections. I've seen examples involving 'slave' and 'master' configurations and have come to understand that (in my case) the slave is the accelerometer and the master is the nRF52840 but there are quite a few examples and I'm unsure as to which would be best suited for my project. I'd appreciate any advice on this too! 

Thanks for your help. 

Parents
  • Hi,

    First you would have to decide on what serial interface that you would like to use.

    Secondly, depending on what serial interface you chose, you should test and understand either the TWI(I2C) or the SPI example.

    The TWI example uses pin 27 and 26 by default, and it's set in the twi_init() function:

    void twi_init (void)
    {
        ret_code_t err_code;
    
        const nrf_drv_twi_config_t twi_lm75b_config = {
           .scl                = ARDUINO_SCL_PIN, //Pin 27
           .sda                = ARDUINO_SDA_PIN, // Pin 26
           .frequency          = NRF_DRV_TWI_FREQ_100K,
           .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
           .clear_bus_init     = false
        };
    
        err_code = nrf_drv_twi_init(&m_twi, &twi_lm75b_config, twi_handler, NULL);
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_twi_enable(&m_twi);
    }

    Also, I would suggest that you read a previous thread where we discussed the TWI driver here.

    regards

    Jared 

Reply
  • Hi,

    First you would have to decide on what serial interface that you would like to use.

    Secondly, depending on what serial interface you chose, you should test and understand either the TWI(I2C) or the SPI example.

    The TWI example uses pin 27 and 26 by default, and it's set in the twi_init() function:

    void twi_init (void)
    {
        ret_code_t err_code;
    
        const nrf_drv_twi_config_t twi_lm75b_config = {
           .scl                = ARDUINO_SCL_PIN, //Pin 27
           .sda                = ARDUINO_SDA_PIN, // Pin 26
           .frequency          = NRF_DRV_TWI_FREQ_100K,
           .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
           .clear_bus_init     = false
        };
    
        err_code = nrf_drv_twi_init(&m_twi, &twi_lm75b_config, twi_handler, NULL);
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_twi_enable(&m_twi);
    }

    Also, I would suggest that you read a previous thread where we discussed the TWI driver here.

    regards

    Jared 

Children
  • Hi Jared, 

    Thanks for the information. I've been reading through the TWI and SPI examples and the SPI Slave example looks like it might be suitable for my application: https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v17.0.2%2Ftwi_sensor_example.html&cp=7_1_4_6_43 

    However, I'm unsure as to what it means by hardware configuration statements such as:

    'Slave SCLK pin must be connected to Master SCLK.

    Slave CS pin must be connected to Master CS.

    Slave MOSI pin must be connected to Master MOSI.

    Slave MISO pin must be connected to Master MISO.'

    I've looked through section 1.4 of my accelerometer's data sheet and assuming it's the slave in this case, I've come to understand that the relevant pin names: 'SCLK, CS, MOSI, MISO' in the nRF52840 SPI Slave example correspond to the pin names: 'SCL, SCS, SDA, SDO' for the accelerometer, respectively. Is that correct? I've attached the data sheet in case you're able to have a look and point me in the right direction, it would be greatly appreciated: https://mcubemems.com/wp-content/uploads/2020/03/EV3672AB-Quick-Start-Guide-and-Demo-APS-045-0017v1.5.pdf

    I'm aiming to use only one nRF52840 DK and to connect it to the accelerometer mounted on a breadboard so that the DK can transmit output values to my Mac via BLE. Would you say this is feasible?

    Most examples include the use of two DKs. For example, in step 3 of testing the SPI Slave example I'm prompted to 'Connect the board to another board that runs the SPI Master Example' but I'm using a single board so I'm unsure if this example will work. Do you know of any examples that use a single nRF52840 board to communicate directly to a target PC/Mac? 

    Thank you. 

  • Jaz said:

    Thanks for the information. I've been reading through the TWI and SPI examples and the SPI Slave example looks like it might be suitable for my application: https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v17.0.2%2Ftwi_sensor_example.html&cp=7_1_4_6_43 

    However, I'm unsure as to what it means by hardware configuration statements such as:

    'Slave SCLK pin must be connected to Master SCLK.

    Slave CS pin must be connected to Master CS.

    Slave MOSI pin must be connected to Master MOSI.

    Slave MISO pin must be connected to Master MISO.'

    I've looked through section 1.4 of my accelerometer's data sheet and assuming it's the slave in this case, I've come to understand that the relevant pin names: 'SCLK, CS, MOSI, MISO' in the nRF52840 SPI Slave example correspond to the pin names: 'SCL, SCS, SDA, SDO' for the accelerometer, respectively. Is that correct? I've attached the data sheet in case you're able to have a look and point me in the right direction, it would be greatly appreciated: https://mcubemems.com/wp-content/uploads/2020/03/EV3672AB-Quick-Start-Guide-and-Demo-APS-045-0017v1.5.pdf

     Yes, that is correct. Slaves that use the same pins for both SPI and TWI(I2C) usually use that kind of naming convention.

     

    Jaz said:

    I'm aiming to use only one nRF52840 DK and to connect it to the accelerometer mounted on a breadboard so that the DK can transmit output values to my Mac via BLE. Would you say this is feasible?

    Most examples include the use of two DKs. For example, in step 3 of testing the SPI Slave example I'm prompted to 'Connect the board to another board that runs the SPI Master Example' but I'm using a single board so I'm unsure if this example will work. Do you know of any examples that use a single nRF52840 board to communicate directly to a target PC/Mac? 

    Feasible Yes, not sure how you would do it though. You would have to implement the PC side yourselves, as all of our reference design, examples etc expects the PC side to be connected to a Nordic device. It isn't as easy as just connecting to the device via BLE, you have to make a program that can access the BLE on your PC, connect to the peripheral and read the characteristics. 

    Good luck.

    Jared 

Related