This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Connecting Altimeter to nrf52 dk using i2c.

Hi I trying to connect Altimeter ( mpl 3115a2) to the nrf52 development kit. Can someone guide me how to do it (pin connection). I have followed the example given in the sdk but still I am a little unclear. Thank you.

Parents
  • In the twi_master_with_twis_slave example the pins and twi/s instances are defined in the file config.h:

    #define TWI_SCL_M                3   //!< Master SCL pin
    #define TWI_SDA_M                4   //!< Master SDA pin
    
    #define MASTER_TWI_INST          0    //!< TWI interface used as a master accessing EEPROM memory
    

    The macros are used in twi_master_init():

        const nrf_drv_twi_config_t config =
        {
           .scl                = TWI_SCL_M,
           .sda                = TWI_SDA_M,
    ...
    

    So in the example you can change TWI_SCL_M and TWI_SDA_M to be 27 and 26 respectively to match your circuit.

    The simulated EEPROM (slave) address is also defined in config.h:

    #define EEPROM_SIM_ADDR          0x50 //!< Simulated EEPROM TWI address
    

    and the address is used like so:

        static ret_code_t eeprom_read(size_t addr, uint8_t * pdata, size_t size)
        {
    ...
               ret = nrf_drv_twi_tx(&m_twi_master, EEPROM_SIM_ADDR, &addr8, 1, true);
    ...
               ret = nrf_drv_twi_rx(&m_twi_master, EEPROM_SIM_ADDR, pdata, size, false);
    ...
        }
    

    So EEPROM_SIM_ADDR above would in your altimeter's case be changed to 0xC0 (datasheet p.6. ; 7bit address 0x60 << 1). Otherwise the reads and writes are done similarly to how they're done in the example.

    As for the read/write (register) addresses, you need to follow e.g. the sequence in MPL3115A2 datasheet p.10. IIC_RegWrite/Read are analogous to eeprom_write/read in the example (size=1).

    I hope I managed to answer your question and didn't just blabber something... :)

  • Yes with nrf_drv_twi_tx you write. First the register address, then the data. Like in the eeprom_write example function, something like

    uint8_t target_register = 0x26;
    nrf_drv_twi_tx(&m_twi_master, ALTIMETER_ADDRESS, &target_register, 1, true);
    uint8_t data_to_write = 0xB8;
    size_t size = sizeof(data_to_write);
    nrf_drv_twi_tx(&m_twi_master, ALTIMETER_ADDRESS, &data_to_write, size, false);
    
Reply
  • Yes with nrf_drv_twi_tx you write. First the register address, then the data. Like in the eeprom_write example function, something like

    uint8_t target_register = 0x26;
    nrf_drv_twi_tx(&m_twi_master, ALTIMETER_ADDRESS, &target_register, 1, true);
    uint8_t data_to_write = 0xB8;
    size_t size = sizeof(data_to_write);
    nrf_drv_twi_tx(&m_twi_master, ALTIMETER_ADDRESS, &data_to_write, size, false);
    
Children
No Data
Related