AnsweredAssumed Answered

TWI Driver Sends Only 1 Byte

Question asked by spflanze on Jan 25, 2013
Latest reply on Feb 7, 2013 by SachinV

In the below code snippets I need three bytes of the buffer DataBufferOutbound to be sent on the TWI bus. I can see on the scope only one byte is being sent, and its value is 1. The values in DataBufferOutbound are ignored. I need to know what is wrong.

 

The below code is a representation of the sequence the relevant statements are executed in. Irrelevant code is excluded:

 

// 3 bytes are needed to write a command ( 1 for address plus 2 for data)

// 2 bytes are needed to read data.

// Both of these are sized to 4 to align on 32 bit boundaries:

static unsigned char DataBufferOutbound[4];

static unsigned char DataBufferInbound[4];

 

// The Buffers Instantiated:

// One is required for sending a command and two are required to query.

static ADI_DEV_SEQ_1D_BUFFER pot_SeqBuffer[2];

const adi_twi_bit_rate pot_bit_rate = { .frequency = 100, .duty_cycle = 50 };

 

ADI_DEV_CMD_VALUE_PAIR TWIConfig[] = {

    { ADI_TWI_CMD_SET_HARDWARE,                (void *)ADI_INT_TWI1 }, // select a hardware TWI port (pass ADI_INT_PERIPHERAL_ID of hardware)

    { ADI_DEV_CMD_SET_DATAFLOW_METHOD,    (void *)ADI_DEV_MODE_SEQ_CHAINED},

    { ADI_TWI_CMD_SET_FIFO,                      (void *)0x0000 }, // set FIFO interrupt levels

    { ADI_TWI_CMD_SET_RATE,                        (void *)&pot_bit_rate }, // select the frequency and duty cycle (pass adi_twi_bit_rate struct)

    { ADI_TWI_CMD_SET_LOSTARB,              (void *)1 }, // set number of retries before reporting LOSTARB

    { ADI_TWI_CMD_SET_ANAK,                      (void *)10 }, // set number of retries before reporting ANAK

    { ADI_TWI_CMD_SET_DNAK,                      (void *)10 }, // set number of retries before reporting DNAK

    { ADI_DEV_CMD_SET_DATAFLOW,                (void *)TRUE },

    { ADI_DEV_CMD_END,                    NULL } // Terminator element

};

 

u32 Init(void){

     twi1_Init_result = adi_dev_Open(

                adi_dev_ManagerHandle,

                &ADITWIEntryPoint,

                1,  // TWI Device Number

                NULL, // Client Handle ( passed to call back function )

                &twi1_DeviceHandle,

                ADI_DEV_DIRECTION_BIDIRECTIONAL,

                NULL, // DMA Handle (TWI has no DMA)

                adi_dcb_QueueHandle, //Handle to the deferred callback service deferred.

                twi1_ClientCallback // Call Back Function.

          );

      // Set values in the chain's outbound buffer element:     

      pot_SeqBuffer[0].Buffer.Data            = (void *)DataBufferOutbound;

     

      // Set to 3 for commands, and 2 for queries

      pot_SeqBuffer[0].Buffer.ElementCount   = 3;

     

      pot_SeqBuffer[0].Buffer.ElementWidth   = 1;

      pot_SeqBuffer[0].Buffer.CallbackParameter = (void *) 1;    // no callback

 

      // Set to NULL for commands, set to (ADI_DEV_1D_BUFFER *)&pot_SeqBuffer[1]

      // for queries.

      pot_SeqBuffer[0].Buffer.pNext = (ADI_DEV_1D_BUFFER *)&pot_SeqBuffer[1];

     

      pot_SeqBuffer[0].Buffer.pAdditionalInfo = (void*)NULL;

      pot_SeqBuffer[0].Direction = ADI_DEV_DIRECTION_OUTBOUND;

 

      // Set values in the chain's inbound buffer element:     

      pot_SeqBuffer[1].Buffer.Data     = (void *)DataBufferInbound;

      pot_SeqBuffer[1].Buffer.ElementCount = 2;

      pot_SeqBuffer[1].Buffer.ElementWidth = 1;

      pot_SeqBuffer[1].Buffer.CallbackParameter = (void *) 2;

      pot_SeqBuffer[1].Buffer.pNext = (void *)NULL;     // end of chain

      pot_SeqBuffer[1].Buffer.pAdditionalInfo = (void*)NULL;

      pot_SeqBuffer[1].Direction = ADI_DEV_DIRECTION_INBOUND;

 

     adi_dev_Control(twi1_DeviceHandle, ADI_DEV_CMD_TABLE, (void*)TWIConfig))

 

      // Set up test values to see on the oscilloscope:

      int i;

      for( i=0; i<3; i++ ){

       DataBufferOutbound[i] = 0xAA;

    }

 

   // Configure buffer for command send:

   pot_SeqBuffer[1].Buffer.ElementCount = 3;

   pot_SeqBuffer[0].Buffer.pNext = (void*)NULL;

   

   // This function call sends only one byte instead of the expected three, and only that byte's least significant bit is set:

   Result = adi_dev_SequentialIO(twi1_DeviceHandle, ADI_DEV_SEQ_1D, (ADI_DEV_BUFFER *)pot_SeqBuffer);

}

Outcomes