Post Go back to editing

how can i write/read two bytes to the TWI interface using ADSP21489?

Hi  everyone

                I ues the TWI interface of SHARC reading the tempereture sensor.Now, i use the example of the Power_On_Self_Test  and  i can write/read one byte data to the TWI interface. But i can not  write/read two bytes to the TWI interface.

              MY slave is the tmp112,i read the datasheet, the time diagram is below.

   

//THE CODE        

void I2C_Master_Write (unsigned int data, unsigned int address)
{

/* setup flag */
g_write_pend = 1;

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

/* enable master transfer complete and TX FIFO service interrupts */
*pTWIIMASK = TWIMCOM | TWITXINT;

/* setup for 2 data bytes, master enable, master TX */
*pTWIMCTL = TWIDCNT2 | TWIMEN;

/* wait for data */
while ( g_buff_empty != 1 )
{
;
}

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

/* reset flag */
g_buff_empty = 1;

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

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

/* reset flag */
g_buff_empty = 1;

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

}


int Read_TWI_Register(int address)
{
int temp; /* temporary int */


/* 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 */
temp = *pRXTWI8;

return temp;
}

catching  the wave from the OSC

the write

the read

hope someone can give me some advice,thanks.

                                                                              jack

attachments.zip
Parents Reply Children
No Data