commit 2a008be5630ea3fc3383bfed9f65e0065b0c3d33 Author: Wolfgang Hottgenroth Date: Fri Oct 4 07:28:32 2019 +0100 initial diff --git a/snippets/spi.py b/snippets/spi.py new file mode 100644 index 0000000..3d0a8cc --- /dev/null +++ b/snippets/spi.py @@ -0,0 +1,74 @@ +import struct +import wiringpi +import time + + + +def ISR(): + wiringpi.digitalWrite(16, 1) + + + +wiringpi.wiringPiSetupGpio() +SPIchan = 0 +SPIspeed = 1000000 +wiringpi.wiringPiSPISetup (SPIchan, SPIspeed) +wiringpi.pinMode(16, wiringpi.OUTPUT) +wiringpi.digitalWrite(16, 0) +wiringpi.pinMode(19, wiringpi.INPUT) +wiringpi.wiringPiISR(19, wiringpi.INT_EDGE_FALLING, ISR) + + + +clr_mdr0 = 0b00001000 +clr_mdr1 = 0b00010000 +clr_cntr = 0b00100000 +clr_str = 0b00110000 + +rd_cntr = 0x60 +rd_otr = 0x68 + +rd_str = 0x70 +rd_mdr0 = 0x48 +rd_mdr1 = 0x50 + +load_cntr2otr = 0b11100000 + + +def write(c): + buf = bytes([c]) + retlen, retdata = wiringpi.wiringPiSPIDataRW(SPIchan, buf) + +def read5(c): + buf = bytes([c,0,0,0,0]) + retlen, retdata = wiringpi.wiringPiSPIDataRW(SPIchan, buf) + v = struct.unpack('>I', retdata[1:])[0] + return v + +def read2(c): + buf = bytes([c,0]) + retlen, retdata = wiringpi.wiringPiSPIDataRW(SPIchan, buf) + v = struct.unpack('>B', retdata[1:])[0] + return v + + + +#write(clr_mdr0) +#write(clr_mdr1) +#write(clr_cntr) + + +write(clr_cntr) +write(clr_str) + + +while True: + x = read2(rd_str) + y = read5(rd_cntr) + + print("{0} {0:#04x} {0:#010b}".format(x)) + print(y) + print + + time.sleep(1.0) + diff --git a/snippets/test1/test1 b/snippets/test1/test1 new file mode 100755 index 0000000..53b72c0 Binary files /dev/null and b/snippets/test1/test1 differ diff --git a/snippets/test1/test1.c b/snippets/test1/test1.c new file mode 100644 index 0000000..31a3069 --- /dev/null +++ b/snippets/test1/test1.c @@ -0,0 +1,17 @@ +#include + +void isr() { + static int t = 0; + digitalWrite(16, t); + t = ! t; +} + + +int main (void) { + wiringPiSetupGpio() ; + pinMode(16, OUTPUT); + pinMode(19, INPUT); + wiringPiISR(19, INT_EDGE_FALLING, isr); + + while(1); +}