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....

Parents
  • 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.

  • Please remind always check the hardware at first , almost troubles from hardware side.

    1. Check the pin assign as same as the software defined
    2. Check the voltage of VDD/SDA/SCL pins
    3. Check the the device address , if its a flexible addressing device ,make sure the schematic is same as you defined in software.
    4. Check your pin assign to arduino .

    After check the hardware finish. Next check the timing digram is correct by using oscilloscope or i2c logic analyzer. If it not same as sensor specification , it strongly problem in software.

Reply
  • Please remind always check the hardware at first , almost troubles from hardware side.

    1. Check the pin assign as same as the software defined
    2. Check the voltage of VDD/SDA/SCL pins
    3. Check the the device address , if its a flexible addressing device ,make sure the schematic is same as you defined in software.
    4. Check your pin assign to arduino .

    After check the hardware finish. Next check the timing digram is correct by using oscilloscope or i2c logic analyzer. If it not same as sensor specification , it strongly problem in software.

Children
No Data
Related