AnsweredAssumed Answered

TWI Interface

Question asked by neoplay on Nov 22, 2013
Latest reply on Dec 19, 2013 by VineethaThomas

I am learning the Blackfin by following some sample code. Now I am studying how TWO works and here are some codes;

 

function prototype:

 

void TWI_MasterMode_Write(unsigned short DeviceAddr, unsigned char *TWI_Data_Pointer, unsigned short Count, unsigned short TWI_Length);

 

variable for the function

 

unsigned char RightLineIn[] =                     { 0x02, 0x01b};

 

Function calling

 

TWI_MasterMode_Write( CODEC_TWI_ADDRESS, RightLineIn, 1, 2);

 

An the function in details

 

/*******************************************************************

*   Function:    TWI_MasterMode_Write

*   Description: do a master mode write

*******************************************************************/

void TWI_MasterMode_Write(unsigned short DeviceAddr, unsigned char *TWI_Data_Pointer, unsigned short Count, unsigned short TWI_Length)

{

          int i, j, timeout;

 

  *pTWI_FIFO_CTL = 0;                                                                                          /* clear the bit manually */

          *pTWI_CONTROL = TWI_ENA | PRESCALE_VALUE;                              /* PRESCALE = fsclk/10MHz */

          *pTWI_CLKDIV = ((CLKDIV_HI) << 8) | (CLKDIV_LO);          /* CLKDIV = (1/SCL)/(1/10MHz) */

          *pTWI_MASTER_ADDR = DeviceAddr;                                                            /* target address (7-bits plus the read/write bit) */

 

 

          for (i = 0; i < Count; i++)

          {

              /* # of configurations to send */

                    *pTWI_XMT_DATA8 = *TWI_Data_Pointer++;          /* pointer to data */

                    ssync();

 

                    *pTWI_MASTER_CTL = (TWI_Length<<6) | MEN;          /* start transmission */

 

 

                    timeout = 0x1000;

 

                    for (j = 0; j < (TWI_Length-1); j++)

                    {

                        /* # of transfers before stop condition */

                              while ((*pTWI_FIFO_STAT == XMTSTAT) && --timeout)          /* wait to load the next sample into the TX FIFO */           // TAR37913

                              {

                                        asm("nop;");

                                        asm("nop;");

                                        asm("nop;");

                                        ssync();

                              }

                              if(!timeout)

                                        return;

 

 

                              *pTWI_XMT_DATA8 = *TWI_Data_Pointer++;                    /* load the next sample into the TX FIFO */

                              ssync();

                    }

 

 

                    while ((*pTWI_INT_STAT & MCOMP) == 0)                              /* wait until transmission complete and MCOMP is set */

                              ssync();

 

 

                    *pTWI_INT_STAT = XMTSERV | MCOMP;                                        /* service TWI for next transmission */

          }

 

 

          asm("nop;");

          asm("nop;");

          asm("nop;");

}

 

My question why is function variable RightLineIn a array, not a number and how is it been used in the function.

 

 

 

Thanks for your help

 

 

 

 

--Neo

Outcomes