Post Go back to editing

TWI polling (no interrupt)

Hi,

We are working on the ADSP-21489 Ez-Board on CCES.

A part of the project deals with TWI. The code works properly with interrupt (similar to the temp_sensor_test code in Power_On_SelfTest example).

But we would like to make it working without interrupt, so by polling fifo status registers.

I took a look to some example files posted on this forum, but did not find any solution to make it working.

Attached is the code, could someone take a look and tell me if I missed something or if something is not doing right?

We use 2 kind of reading: 8bit and 16bit, and 1 kind of writing: 8bit.

Thank you for your help,

Marc

TWI.c.zip
  • Hi,

    I found the way to do it actually.

    And there was something weird happening with the TWIFIFOSTAT register. It was missing some data in this kind of polling...

    As an advice for people who would like to do a poll for TWI, here is how I poll for a read and for a write:

    unsigned int Read_TWI_Register(unsigned int address)

    {

              *pTWIMADDR = I2C_ADDRESS;

              *pTXTWI8 = address;                                                            //Pre-configure the first byte we are sending (the register address)

              *pTWIMCTL = TWIDCNT1 | TWIMEN;                              //Indicate 1 byte to be transferred (the register address)

              while(!(*pTWIIRPTL & TWITXINT));                    //Use interrupt-related flags to determine when the fifo has become empty

              *pTWIIRPTL |= TWITXINT;                                                  //Clear the interrupt flag so it can be used again in the future

              while(!(*pTWIIRPTL & TWIMCOM));                              //Before we leave, wait for the master transfer to be completed

              *pTWIIRPTL |= TWIMCOM;                                                  //Clear the interrupt flag so it can be used again in the future

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

              while(!(*pTWIIRPTL & TWIMCOM));                              //Wait for the master transfer to be completed (I2C bus is completely released)

              *pTWIIRPTL |= TWIMCOM;                                                  //Clear the interrupt flag so it can be used again in the future

              return *pRXTWI8;                                                            //read data from the 8-bit RX fifo

    }

    void Write_TWI_Register(unsigned int address, unsigned int data)

    {

              *pTWIMADDR = I2C_ADDRESS;

              *pTXTWI8 = address;                                                            //Pre-configure the first byte we are sending (the register address)

              *pTWIMCTL = TWIDCNT2 | TWIMEN;                              //Indicate 2 bytes to be transferred (the register address and the data)

              while(!(*pTWIIRPTL & TWITXINT));                    //Use interrupt-related flags to determine when the fifo has become empty

              *pTWIIRPTL |= TWITXINT;                                                  //Clear the interrupt flag so it can be used again in the future

              *pTXTWI8 = data;                                                            //Write the data we want

              while(!(*pTWIIRPTL & TWITXINT));                    //Use interrupt-related flags to determine when the fifo has become empty

              *pTWIIRPTL |= TWITXINT;                                                  //Clear the interrupt flag so it can be used again in the future

              while(!(*pTWIIRPTL & TWIMCOM));                              //Before we leave, wait for the master transfer to be completed

              *pTWIIRPTL |= TWIMCOM;                                                  //Clear the interrupt flag so it can be used again in the future

    }

    I used the TWIIRPTL instead of the FIFO status register and it is working well.

    Also I check the TWI master transfer complete each time I write.

    Marc

  • This question has been closed by the EZ team and is assumed answered.