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. 

  • 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 

  • 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 

  • Thanks for your reply.

    I'm thinking of using the nRF52840 dongle attached to my Mac for the PC side, then have the DK and accelerometer as a separate circuit as previously mentioned. The accelerometer data would be transferred to the dongle via BLE and then to my Mac through the USB port. I'd be grateful if you could point me to example code similar to this? I'm just not sure about where to begin in terms of interfacing the accelerometer with the DK, any examples or pieces of code would be appreciated! 

  • Hi,

    So the first thing you should do is to test and understand the NUS example in the SDK. It transmit data it has received from UART over BLE. The NUS peripheral example also has a NUS Central example that you can flash to a device that acts as a Central. That way you have a BLE link that can get data from serial com send it over BLE to another device that outputs the data over serial. After you have tested the example you should replace the UART with the SPI/I2C. I'm certain that this has been done before in this forum. Search the forum on already existing threads regarding this. If you want to communicate through the USB peripheral on the dongle instead of the UART pins than the USBD BLE UART example is the one you should use. 

    Next, you would want to port the NUS example that you're going to run on the computer side to the Dongle. None of the previous mentioned examples supports the Dongle "straight-out-of-the-box". You would have to convert the example so that it uses the correct board file and preprocessor settings. Luckily, we have already made a tutorial on this, so it shouldn't be a big thing. 

    Some threads that you could be of help along the way

    regards
    Jared 

Related