AnsweredAssumed Answered

Sharc EZ Kit TWI (I2C) Interrupt Not Firing

Question asked by seanmichnowski on Nov 27, 2012
Latest reply on Dec 6, 2012 by seanmichnowski

Hello,

 

I am using an ADSP-21469 EZ-Kit, trying to talk with the onboard temperature sensor ADM1032 via TWI (I2C).  I am unable to read or write to the sensor.  I am trying 2 methods for TWI access: interrupt mode (taken from the ez-kit's example code) and core-access mode.  On the dev. board, DIP switch 3 has positions 7 and 8 turned ON, to allow DPI_7 and DPI_8 to connect to TEMP_SDA and TEMP_SCK of the temperature sensor, respectively.

 

Code for writing to a register is below (without interrupt):

// ============================================
// SRU initialization
// TWI data output connected to DPI pin 7 input
// DPI pin 7 output connected to TWI data input
// TWI clock connected to DPI pin 8
// ============================================
SRU(LOW,DPI_PB01_I);
SRU(LOW,DPI_PB02_I);
SRU(LOW,DPI_PB07_I);
SRU(LOW,DPI_PB08_I);
SRU(TWI_DATA_PBEN_O,DPI_PBEN07_I);
SRU(DPI_PB07_O, TWI_DATA_I);
SRU2(TWI_CLK_PBEN_O,DPI_PBEN08_I);

//Writing 1 byte at a time
void I2C_Master_Write (unsigned int data, unsigned int register_address)
{
    *pTWIMITR = 0x000014;
    *pTWIDIV  = 0x0000C0D; //For Fast Mode 400KHz
    *pTWIFIFOCTL = TWITXFLUSH | TWIRXFLUSH;
    *pTWIFIFOCTL = 0;    
    *pTWIMCTL = TWIMEN | TWIFAST | (1<<6);

    *pTWIMADDR = 0x4C; //temperature sensor/slave address 

    *pTXTWI8 = register_address; //register address in temp sensor to write data
    
    
    *pTWIMCTL = TWIMEN | TWIFAST |(1<<6) | TWIRSTART;

    while(*pTWIFIFOSTAT & TWITXS) {};

    *pTXTWI8 = data;
    while(*pTWIFIFOSTAT & TWITXS) {};

    while(*pTWIMSTAT & TWIMPROG) {};

}

 

Execution never gets past line 31, the register address never gets transmitted.

 

 

Code taken as-is from the example program is below.  In the read function, execution never gets past the while loop in line 39 because the interrupt never gets called to clear the write pending flag.

 

// configure SRU
SRU(LOW,DPI_PB07_I);
SRU(TWI_DATA_PBEN_O,DPI_PBEN07_I);
SRU(DPI_PB07_O, TWI_DATA_I);
SRU(LOW,DPI_PB08_I);
SRU2(TWI_CLK_PBEN_O,DPI_PBEN08_I);

/* setup the interrupt */
*pPICR0 = TWI_INTERRUPT;
interrupt( SIG_P0, TempSensor_ISR );

// setup TWI
*pTWIMITR = 20 | TWIEN;                /* reference clock = 159.7/16=9.984 MHz */
*pTWIDIV = 0x6464;                    /* SCL clock divider, high and low */
*pTWIMADDR = TEMP_SENSOR_ADDRESS;    /* device address specific to temp sensor */
*pTWIFIFOCTL = TWIBHD;                /* read/write happens regardless of FIFO status */


/*******************************************************************
*   Function:    Read_TWI_Register
*   Description: Returns value of a TWI register based on specified address.
*******************************************************************/
int Read_TWI_Register(int address)
{
    /* setup flags, to read we do both write and read */
    g_write_pend = 1;
    g_read_pend = 1;

    /* write address to the 8-bit TX fifo */
    *pTXTWI8 = address;

    /* enable master transfer complete interrupt */
    *pTWIIMASK = TWIMCOM;

    /* setup for 1 data byte, master enable, master TX */
    *pTWIMCTL = TWIDCNT1 | TWIMEN;

    /* wait for write to complete */
    while( g_write_pend == 1 )
    {
    }

    /* setup for 1 data byte, master enable, master RX */
    *pTWIMCTL = TWIDCNT1 | TWIMEN | TWIMDIR;

    /* wait for read to complete */
    while( g_read_pend == 1 )
    {
    }

    /* read data from the 8-bit RX fifo */
    int temp = *pRXTWI8;

    return temp;
}



/*******************************************************************
*   Function:    TempSensor_ISR
*   Description: Handler for the temp sensor ISR.
*******************************************************************/
void TempSensor_ISR(int sig_int)
{
    /* read the processor's TWI interrupt source reg */
    int temp = *pTWIIRPTL;

    /* check master TX complete bit */
    if ( (temp & TWIMCOM) == 0 )
    {
        /* if clear that means a transfer not detected, set empty flag */
        g_buff_empty=1;

        /* clear TX FIFO service bit */
        temp |= TWITXINT;
        *pTWIIRPTL=temp;
    }

    else
    {
        /* else it means master TX is complete, clear this bit */
        temp |= TWIMCOM;
        *pTWIIRPTL=temp;

        /* update our flags */
        if( g_write_pend == 1 )
            g_write_pend=0;
        else
            g_read_pend=0;
    }
}

 

 

 

When using a voltmeter to probe the TWI pins, the SCL pin is at ~15mV and the SDA pin is at ~3.2V.  I believe these values are as expected. 

 

Thank you for the help, and I appreciate your time,

Sean Michnowski

 


Attachments

Outcomes