Created
March 5, 2014 19:10
-
-
Save ersatzavian/9374294 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function uartRead() { | |
| local readValue = ""; | |
| // pause to let partner device finish writing command | |
| // at 9600 baud, it takes about 1.04ms to write a byte | |
| // (8 bits plus start bit and stop bit = 10 bits) | |
| // so, it'll take about 4.16 ms to write a 4-byte word | |
| // we'll wait even longer for demonstration purposes here | |
| imp.sleep(0.005); | |
| // now empty the FIFO | |
| local b = uart.read(); | |
| while (b != -1) { | |
| readValue += format("%c",b); | |
| b = uart.read(); | |
| } | |
| server.log("Got: "+readValue); | |
| } | |
| // configure the UART to use the callback function above | |
| uart <- hardware.uart12; | |
| uart.configure(9600, 8, PARITY_NONE, 1, NO_CTSRTS, uartRead); | |
| // send a command to kick things off | |
| uart.write("AT\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment