Reading an entire microcontroller port

Posted on
  • Is it possible to read an entire port (e.g. PA0 to PA15) at once? In C it's possible, and a lot quicker than reading each pin individually. Or is this how Espruino already works when reading multiple pins?

    Thanks!

  • Well, you can use peek16 with the address of the port to read pins directly (you'd have to check the Microcontroller datasheet for the address).

    However, something like:

    var pins = [A15,A14,A13, .... A0];
    // note - define array of pins before use, so it's faster
    digitalRead(pins); 
    

    Actually works pretty fast - it's not as fast as the peek, but it's loads faster than calling the function 16 different times. So much so that you're unlikely to notice the speed difference between it and peek when calling it from JS.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Reading an entire microcontroller port

Posted by Avatar for AlexOwen @AlexOwen

Actions