You are right, I forgot that part of the errata. I read out the register inside the TSI interrupt routine. However adding a delay of 1 ms does not change the result. For clarity I provide my sourcecode, it is in Arduino style, but I think the general functionality is still understandable.
#define nscn 0 // number of scans
#define pres 0 // scan number prescaler
#define iele 0 // electrode dis-/charge current
#define iref 7 // reference oscillator dis-/charge current
uint16_t val;
double c;
void tsi0_isr() {
delay(1);
val = (TSI0_CNTR9 >> 16) & 0xFFFF; // read content of the output register
TSI0_GENCS |= TSI_GENCS_EOSF;
NVIC_CLEAR_PENDING(IRQ_TSI);
}
void setup() {
Serial.begin(9600);
SIM_SCGC5 |= SIM_SCGC5_TSI; // enable tsi clock
TSI0_GENCS = 0; // reset tsi module
TSI0_PEN = (1 << 9); // enable channel 9 (pin 0) // set dis-/charge currents
TSI0_SCANC |= TSI_SCANC_REFCHRG(iref) | TSI_SCANC_EXTCHRG(iele); // set scan number + prescaler, activate module
TSI0_GENCS |= TSI_GENCS_NSCN(nscn) | TSI_GENCS_PS(pres);
TSI0_GENCS |= TSI_GENCS_TSIIE | TSI_GENCS_ESOR;
TSI0_GENCS |= TSI_GENCS_TSIEN; NVIC_ENABLE_IRQ(IRQ_TSI);
}
void loop() {
TSI0_GENCS |= TSI_GENCS_SWTS;
delay(1000);
// using Figure 50-39. Equation 5 from the reference manual to calculate the capacitance
c = (double)val * (iele + 1) / ((nscn + 1) * (1 << pres) * (iref + 1));
Serial.print(val); Serial.print(": "); Serial.print(c, 8); Serial.println(" pF");
}