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

Parents
  • I have very similar code to yours:

    bool acc_read_registers(uint8_t reg, uint8_t *data, uint8_t size)
    {   bool result = false;
    
        // select first register to be read
        if(twi_master_transfer(TWI_MASTER_CONFIG_MMA7660_ADDRESS, &reg, 1, TWI_DONT_ISSUE_STOP))
        {
            // read bytes and finish transaction
            result = twi_master_transfer(TWI_MASTER_CONFIG_MMA7660_ADDRESS | TWI_READ_BIT, data, size, TWI_ISSUE_STOP);
        }
        
        return(result);
    }
    

    and it works correctly with both TWI versions (s/w that you are using and h/w that talks by means of TWI peripheral). I'm using SDK 7.0.1 - which one you are working with?

    If you think that it could be problem in TWI driver, you may always switch to its another version - just replace file twi_sw_master.c with twi_hw_master.c and from now all timings will be controlled by h/w.

    Not really sure what is exactly your problem - is there error reported during read or you are getting wrong data? The fragment of twi_sw_master.c file you have shown should read 8 bits only, just after this loop ACK or NACK is generated depending if that is last byte.

  • Thank you. But .. Where is the SDK 7.0.1 ?? I can't find SDK 7.0.1 .. How to Download SDK 7.0.1 ? My SDK version v5.1.0

Reply Children
No Data
Related