A simple trick
I ran out of I/O pins on the PIC18F14K22 But really needed to check if a MMC (SDcard) was in the slot, to avoid long timeouts for the software to try to read it, as the system must immediately switch to EEPROM if no card is present. Now how to do this? The switch on the SDcard connector switches to ground when a card is inserted, not very useful to short some other signal for detection. Thought about it, SPI SDO (output from card is only used here for the card, not for anything else. Normally SPO is pulled up with a pullup or driven low / high by card when it responds. So...
+3.3 +3.3 | | card socket 68k 68k R2 required switch, closed | R1 | pullup by spec if card in slot | |------------------->---- SDO------ PIC input GND ----- | c | ^------------------- b NPN BC548 1k R3 S1 e Q1 | | SDO /// from cardSo, when no card is in the card connector then S1 is open, Q1 conducts, and SPO is low, and PIC reads this, and knows it has to use something else than the SDCard to store data, a 24LC1025 EEPROM. When the card is inserted all becomes according to spec, and SDO is high, until activated by the card. R3 prevent the card output being shorted by Q1,
Just tested it, works great.