TSI EOSF bit polling problem.

Showing results for 
Search instead for 
Did you mean: 

TSI EOSF bit polling problem.

Contributor II


I've been trying to write my own TSI procedure which is heavily based on this example : Using the touch interface on the Freescale Freedom Development Platform « The Embedded Beat: Freesca...

Everything seems to work fine untill i reach "while(!(TSI0_GENCS &= TSI_GENCS_EOSF_MASK));" command.  Kl25z is running 48MHz in PEE mode.

Debugger shows that whole GENC register is cleared  as soon as i'm checking  if scan is completed. Do you have any clues, hints ?

I'm looking forward to your reply.

My code is showed below:

void TSI_init(void)


  SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK; //sygnał zegarowy na PORTB

  SIM_SCGC5 |= SIM_SCGC5_TSI_MASK;  // sygnał zegarowy na moduł TSI

  // Enable GPIO pins as TSI channels

  PORTB_PCR16 |= PORT_PCR_MUX(0);            // multipleks PTB16 as TSI channel 9

  PORTB_PCR17 |=  PORT_PCR_MUX(0);        // multipleks PTB17 as TSI channel 10


  | TSI_GENCS_MODE(0)        // Non-noise detection -> tylko dla srodowisk z dużymi zakłoceniami EMI

  | TSI_GENCS_REFCHRG(4)        // 8 micro-amp charge ->prąd referencjnego oscylatora

  | TSI_GENCS_DVOLT(0)        // Set voltage rails -> ustaw szyny Vp=1,33V Vmin=0,30V

  | TSI_GENCS_EXTCHRG(7)    // Set charge/discharge current -> prąd oscylatora zewnętrznego 64uA

  | TSI_GENCS_PS(4)        // Frequency divided by 16 -> częstotliwosć oscylatora zewnętrznego

  | TSI_GENCS_NSCN(11)        // Scan electrode count -> skanuj elektrodę 12x

    //| TSI_GENCS_TSIIEN_MASK     // interrupts

  | TSI_GENCS_STPE_MASK // pozwol na prace TSI w kazdym z trybów pracy procesora

  //             | TSI_GENCS_STM_MASK     // Scan trigger type software

  // 0 = software



  // Do not enable TSI module until all other settings are in place!

  TSI0_GENCS |= TSI_GENCS_TSIEN_MASK; // włączenie modułu TSI, zeby zmienic powyzsze opcje nalezy wylaczyc modul,zmienic ustawienia i z powrotem wlaczyc TSI




} // End InitTSI()

void CalibrateTSI(void)


TSI0_GENCS |= TSI_GENCS_EOSF_MASK;     // Clear end of scan flag

// Scan first electrode (TSI9)


TSI0_DATA |= TSI_DATA_SWTS_MASK;           // Request scan

while(!(TSI0_GENCS &= TSI_GENCS_EOSF_MASK)); // poczekaj az skanowanie dobiegnie konca-> EOSF=1

TSI0_GENCS |= TSI_GENCS_EOSF_MASK;        // zeruj flage zakonczenia skanowania -> wpisz 1 do EOSF

kalibracja[0] = (TSI0_DATA &=TSI_DATA_TSICNT_MASK); // zapisz wynik skanowania pierwszej elektrody do tablicy

// Scan second electrode (TSI10)


TSI0_DATA |= TSI_DATA_SWTS_MASK;            // Request scan

while(!(TSI0_GENCS &= TSI_GENCS_EOSF_MASK));    // Spin until done

TSI0_GENCS |= TSI_GENCS_EOSF_MASK;        // Clear end of scan flag

kalibracja[1] = (TSI0_DATA &= TSI_DATA_TSICNT_MASK);

TSI0_DATA |=TSI_DATA_TSICH(9);    // Select electrode to scan

currentElectrode = 0;            // Set flag for first electrode


Labels (1)
0 Kudos
2 Replies

NXP Employee
NXP Employee

Hi, Piesta

I checked your code. I think you might forget one item in your code. You disable software trigger in your TSI initial function. But you forget to enable it in your calibration function. Please help to check again.

Hope my reply can help you.

Best Regards


0 Kudos

Contributor II

Well I've checked everything once again and finally found problem.

There were problem in command "TSI0_GENCS &= TSI_GENCS_EOSF_MASK". It should be just plain & without = . EOSF mask has value 0x04 so that command was clearing whole register because bitwise AND assigment.

0 Kudos