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

Twi problem. How to read data(not include ACK)?

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.

MMA8452Q DataSheet MMA8452Q.pdf

Multiple Byte Read

Master:--------ACK------ACK------ACK...

Slave:ACK:Data---Data----Data---...

// MSB first
for (uint_fast8_t i = 0x80; i != 0; i>>=1)
{
    if (!twi_master_wait_while_scl_low())
    {
        transfer_succeeded = false;
        break;
    }

    if (TWI_SDA_READ())//ACK Receive
    {
        byte_read |= i;
    }
    else
    {
        // No need to do anything
    }

    TWI_SCL_LOW();
    TWI_DELAY();
}

I guess...

This code read (ACK:Data).

But can't read (Data).

How to read Data(not include ACK)?

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

Related