Open Drain mode in the enCore

Question: How do I create an Open Drain mode in the enCore?

 

Answer:

In open drain mode, the pin outputs LOW if the pin's value in the Data Register is '0', and it floats (Hi-Z) if the pin's value in the Data Register is '1'. Because the open drain mode is not available in the enCore's hardware, you need to a little work in firmware to achieve this mode. If the Data Register and Mode 1 are LOW, the pins can be in either: 1- Hi-z mode if Mode 0 is LOW 2- Outputs LOW (sinking current) if Mode 0 is HIGH. This is exactly what open drain mode does. To achieve this, you switch the Mode by writing to the Port Mode Registers. For example, the below piece of code switches the P0.1 Mode 0 bit from '1' to '0' mov A, 01h iowr Por0_Mode0 mov A, 00h iowr Port0_Mode0