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
  • Hi Jack,

    Sorry for the delayed response. Let me work on this and get back you shortly.

    Thanks,

    Jithul

  • The TWI FIFO buffer is configured as a 1-byte-wide, 2-deep transmit FIFO buffer and a 1-byte-wide, 2-deep receive FIFO buffer. The TWI 16-bit FIFO transmit register (TXTWI16) and TWI 16-bit FIFO receive register (RXTWI16) holds a 16-bit data value written into / read from the FIFO buffer respectively. Although peripheral bus reads are 32 bits, a read access to the TXTWI16/RXTWI16 register can only access two receive data bytes from the FIFO buffer. To reduce interrupt output rates and peripheral bus access times, a double-byte receive data access can be performed. Two data bytes can be read, effectively emptying the receive FIFO buffer with a single access.

    You can program the  the TWIFIFOCTL register to indicate if transmit (or receive) FIFO buffer interrupts should occur with each byte transmitted (received) or with each 2 bytes transmitted (received). So could you please check with 16-bit standard mode transfer and see if it meets your requirement. 

  • This question has been assumed as answered either offline via email or with a multi-part answer. This question has now been closed out. If you have an inquiry related to this topic please post a new question in the applicable product forum.

    Thank you,
    EZ Admin
  • Hello  jack,

     I have a similar issue, I am not able to read the temperature values from the tmp112 sensor (It shows the value as 0). My read and write function are similar to yours and I have made the changes suggested by admin. Could you tell me how are communicating with the sensor? 

    Thank you.

  • Hi,

    Apologies for the delay.

    1. Do you have check with 16 bit standard mode transfer?
    2. Are you able to read / write with single byte data without any issue?

    Regards,
    Anand Selvaraj.