6

I have an STM32 with a SIM card reader. For some reason the DETECT pin interrupt is triggered when the SIM card is removed, as opposed to when the SIM card is inserted.

What could be going wrong here?

Randomblue
  • 10,953
  • 29
  • 105
  • 178

2 Answers2

15

Possible reasons I can think of:

  • the card detection switch switches from Vcc instead of ground, so that the logic is inverted and a falling edge becomes a rising edge and vice versa.

  • there's contact bounce, generating both types of edges. Solved with an RC filter.

stevenvh
  • 145,145
  • 21
  • 455
  • 667
1

Sounds like a classic logic inversion problem.

Could be that

  • The signal from the card reader is the opposite polarity to what you expect (as also suggested by stevenvh)
  • The micro is set up to respond to the opposite interrupt edge to what you expect
  • There's a (maybe programmable) inverter within the micro between the pin and the IRQ logic
  • There's an inverting buffer on the micro PCB between the SIM reader and the micro pin

Off-topic for the question, but is it required that you respond to that signal particularly quickly? I'm not sure I see a need for an interrupt on that event, I would've thought just polling in the background loop would be sufficient.

Martin Thompson
  • 8,439
  • 1
  • 23
  • 44
  • The use of an interrupt instead of polling for detecting SIM card insertion has its merits: One avoids a polling loop that would very rarely yield results, wasting cycles the rest of the time. It isn't an uncommon requirement. – Anindo Ghosh Dec 20 '13 at 12:35