This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

(nrf51822-EK) How to read twi Multiple Byte ?

Hi.

My board : nrf51822 -Evaluation Kit ------ mma8452q problem : read_registers(MMA8452_ADDRESS << 1,OUT_X_MSB, 6, rawData); source code : link text

main.c -> readAccelData-> read_registers -> twi_master_transfer(device_address | TWI_READ_BIT, value, size, TWI_ISSUE_STOP);

I can read Single Byte. I can write Single Byte.

But I can't read Multiple Byte.

How to read Multiple Byte?

Could you give me some tips? How to solve this problem..?

Parents
  • The twi_master_transfer() function you refer to is a part of the TWI peripheral driver and is documented here: developer.nordicsemi.com/.../a00769.html

    Here you can see that it takes an argument, data_length, which specifies how many bytes that should be transferred from the data array.

    In the twi_master_transfer() function (in twi_sw_master.c) you can see that it will not continue to clock out bytes if twi_master_clock_byte() returns false. This function returns false if it does not receive an ACK bit from the slave:

    // Read ACK/NACK. NACK == 1, ACK == 0
    transfer_succeeded &= !(TWI_SDA_READ());
    

    You should have a logic analyzer in order to be able to debug the TWI bus.

Reply
  • The twi_master_transfer() function you refer to is a part of the TWI peripheral driver and is documented here: developer.nordicsemi.com/.../a00769.html

    Here you can see that it takes an argument, data_length, which specifies how many bytes that should be transferred from the data array.

    In the twi_master_transfer() function (in twi_sw_master.c) you can see that it will not continue to clock out bytes if twi_master_clock_byte() returns false. This function returns false if it does not receive an ACK bit from the slave:

    // Read ACK/NACK. NACK == 1, ACK == 0
    transfer_succeeded &= !(TWI_SDA_READ());
    

    You should have a logic analyzer in order to be able to debug the TWI bus.

Children
Related