AnsweredAssumed Answered

TSI EOSF bit polling problem.

Question asked by Mateusz Piesta on Nov 2, 2013
Latest reply on Nov 4, 2013 by Mateusz Piesta

Hello,

 

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: Freescale Blog Community

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

 

  TSI0_GENCS |= (TSI_GENCS_ESOR_MASK

  | 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

  

  CalibrateTSI();

  

} // End InitTSI()

 

 

void CalibrateTSI(void)

{

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

 

// Scan first electrode (TSI9)

TSI0_DATA |=TSI_DATA_TSICH(9);

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_TSICH(10);

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

 

}

Outcomes