Bidirectional I/O using InterruptIn and DigitalInOut(OpenDrain)

01 Sep 2010

Hi all.

I tried to read codes of PS/2 with InterruptIn. It's good way to read the signal I checked.PS2_TestProgram

However, I'd like to send commands to a PS/2 device.

The bus is open collector.

So I tried to following codes...

InterruptIn ioIntrIn(p16);
DigitalInOut ioInOut(p16);

void func_fall(void) {
    printf("fall.\n");
}
void func_rise(void) {
    printf("rise.\n");
}

int main() {
    ioIntrIn.fall(&func_fall);
    ioIntrIn.rise(&func_rise);
    ioInOut.mode(OpenDrain);
    ioInOut.output();
    while (1) {
        printf("1\n");
        ioInOut = 1;
        wait(2);

        printf("0\n");
        ioInOut = 0;
        wait(2);
    }
}

I checked the signal and the output messages, It's works. (Maybe)

The point of view ...

  • Reading : using InterruptIn (Need interrupt based I/O)
  • Writing : using DigitalInOut (Need open collector I/O)

Is this right way to provide a bidirectional I/O with InterruptIn on open collector based bus?