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

twi sensor

i am programming nrf-51 dk's program.

i have to get data from sensor, so i am studying example code which is twi_sensor.

i don't know well these function.

nrf_drv_twi_tx(&m_twi_mma_7660, MMA7660_ADDR, reg, sizeof(reg), false);

i know function's parameters is

[in] p_instance TWI instance.
[in] address Address of a specific slave device (only 7 LSB).
[in] p_data Pointer to a transmit buffer.
[in] length Number of bytes to send.
[in] xfer_pending After a specified number of bytes, transmission will be suspended (if xfer_pending is set) or stopped (if not).

but how do i know TWI instance and address Address of a specific slave device?

the example code's parameters that is m_twi_mma_7660, MMA7660_ADDR are acceleration sensor's instance and address.

but i'm going to use heart rate sensor.

and when i execute the example program, nrf_drv_twi_tx returns error.

so it is locked at 'while(m_set_mode_done == false);'.

what is the problem?

ret_code_t err_code;
/* Writing to MMA7660_REG_MODE "1" enables the accelerometer. */
uint8_t reg[2] = {MMA7660_REG_MODE, ACTIVE_MODE};

err_code = nrf_drv_twi_tx(&m_twi_mma_7660, MMA7660_ADDR, reg, sizeof(reg), false);  

APP_ERROR_CHECK(err_code);

while(m_set_mode_done == false);

please let me know. i need help....

  • Maybe I can explain to you. But i think you can try to write a i2c bit-bang protocol , you could be familiar with i2c. The i2c address is shown in your heart rate sensor specification , it usually as 7-bit address. Some sensor i2c address is fixed , some is flexible and determined by hardware pin setting.

    Here's example of flexible address of device - ADXL345. if the ALT_ADDRESS pin pull high , the ADXL345 address would be 0x1D if the ALT_ADDRESS pin grounded , the ADXL345 address would be 0x53

    If you try to read register val with ADXL345, you need send slave address(ADXL345) with write byte at first transmitting. <7bit address>+ So if my ADXL345 address is 0x1D , the full 8bits would be 0x1D<<1.

    Next you need send yours desired register address, it could be 8 bit or greater. The ADXL345 register is 8bit assigned. So you just need send the address of register. Like 0x32 (the high byte data of X-axis)

    Next , you need send the slave address of ADXL345 with read bit , it would be (0x1D<<1)|0x01

    Finally , you can read the data from register.

    So if you want to try hardware twi , refer to the twi api, the theory is the same.

  • thank you very much!!!

    but i cannot understand your answer.....

    could you recommend any books or supplements about basics of these?

    i'm student so i need study more,,,

  • By the way . i dont have this example , so i just geuss the m_set_mode_done is a ack of callback that MMA7660 is enable finish or not.

    The program stuck in here becaue the MMA7660 is not yet ready or other reasons. Please ensure the slave of address, i2c pin assign , pin config is correct. If you have checked above , please check the timing of i2c protocol is right.

  • Im glad i could help you. First , please tell me what board you're using. I'm afraid that you just using the board. It doesnt have other peripheral i2c device. So you send the command to device ,you would never get the result.

  • im using nrf-51 dk and v1.1 sdk alpha.

    excuse me, are you korean?

Related