NXP Comm,
I trying to do touch sensing and simply glow an LED on touch. I am using a MC9S08PT16 controller. I am attaching the link to the datasheet for your reference. Following it, is my code.
Reference Manual (Touch is on page 517): https://www.nxp.com/docs/en/reference-manual/MC9S08PT16RM.pdf
Series Datasheet(Figure 23 is what's relevant): https://www.nxp.com/docs/en/data-sheet/MC9S08PT16.pdf
Code:
interrupt VectorNumber_Vtsi void TSI_ISR() {
TSI_CS0_EOSF = 0;
TSI_CS0_SWTS = 0;
if (TSI_CNT == 0xFFFF)
TSI_CNT |= 0;
LED_RED ^= 1;
}
void InitTSI() {
PORT_PTAIE = 0x00 | PORT_PTAIE_PTAIE6_MASK;
PORT_PTAOE = ~PORT_PTAIE;
PORT_PTAPE = 0x00;
PORT_PTAD = 0x00;
TSI_CS0_TSIEN |= 1;
TSI_CS0_TSIIEN |= 1;
TSI_PEN0_PEN0 = 0x00 | TSI_PEN0_PEN0_MASK;
TSI_CS3_TSICH = 0x00 | TSI_CS3_TSICH0_MASK;
TSI_CS0_STPE |= 1;
TSI_CS1_PS = 0x101;
TSI_CS2_EXTCHRG = 0x100;
TSI_CNT |= 0;
TSI_CS1_NSCN = 0x11111;
}
void main(void) {
int temp;
EnableInterrupts;
clock_config();
system_config();
/*include your code here */
PORT_PTDIE = 0x00;
PORT_PTDOE = ~PORT_PTDIE;
PORT_PTDPE = 0x00;
PORT_PTDD = 0x00;
InitTimer1MsTick();
wdog_disable();
InitTSI();
while (1) {
// TSI_CS0_SWTS |= 1;
if(TSI_CS0_SCNIP == 1);
temp = TSI_CNT;
TSI_CS0_EOSF = 0;
}
}
The understanding I have of touch is that, when there is touch detected, the interrupt flag is set and goes into the ISR automatically. But whats happening is, TSI_CS0_SWTS register is triggering the interrupt, in the datasheet it says its the register that starts the scan again, not sure how its linked to interrupts, because scans are just the 16 bit counter running up and down is what I've understood. Also, one more thing that I didn't understand was the difference between a port and a channel. The touch port is on A6, it mentions in the datasheet as TO1, so I initialized the port and channel both to Zero. I'm pretty sure I've had some misunderstandings with the datasheet. This is my first post on here, just registered !