Adding a setWatch(); after setup of a wired PPI group never fires.
Entering clearWatch() will also inadvertently kill the PPI setup.
Am attempting to simulate an IRQ using the following instructions:
Heading: Interrupts
'Espruino doesn't allow you to react to interrupts from these peripherals directly, however you can change the state of an external pin (see the examples above) and can then short that pin to another pin that you can use as an input with setWatch.'
Setup:
MDBT42Q breakout board with USART edge pins at 12 O'clock
D22 Lower Left corner is set as an 'output' and it feeds a base resisitor of an 2n2222 to drive an LED from it's collector
D20 is an 'input' and is driven by pin D22 with a simple jumper
Watch visually the LED or hang a scope on either pin D20/D22
Execution:
After around a two second wait, a near 100Hz square wave appears on pin D20/D22
The setWatch function never executes.
Entering cw() or clearWatch() will also inadvertently kill the PPI setup.
Some Helper functions and comments removed for brevity
var ll = require("NRF52LL");
// Set up pin as an output -> wire to external resistor 2n2222 base AND to neighboring D20
// Hi out at base turns on 2n2222 collector LED
digitalWrite(D22,0);
digitalRead(D20);
// create a 'toggle' task for the LED
var tog = ll.gpiote(0, {type:"task",pin:D22,lo2hi:1,hi2lo:1,initialState:0});
// set up the rtc
var rtc = ll.rtc(2);
//save slower ~4x ea sec
//poke32(rtc.prescaler, 4095); // 32kHz / 4095 = 8 Hz
poke32(rtc.prescaler, 320); // 32kHz / 320 = ~100 Hz roughy 10msec
//Start
function st() {
rtc.enableEvent("eTick");
poke32(rtc.tStart,1); // start RTC
// use a PPI to trigger the toggle event
ll.ppiEnable(0, rtc.eTick, tog.tOut);
}
var countD20 = 0;
var watchID = {};
// Pulse count the in data on D22
function sw() {
watchID = setWatch(function(e) {
// console.log( "L86 inside sw e.state: " + e.state);
// debugger;
countD20++;
// Display count
// dc();
//},D20,{edge:"rising", data:D20, repeat: true});
//},D20,{edge:"rising", repeat: true});
//},D20,{edge:"both", repeat: true});
},D20,{edge:"falling", repeat: true});
//kills signal at D22
//},D20,true);
//from
//options - If a boolean or integer, it determines whether to call this once (false = default) or every time a change occurs (true).
}
// Display Counter
function dc() {
console.log( "count: " + countD20 );
}
function cw() {
clearWatch();
}
// Wire PPI, init setWatch, start RTC
setTimeout( function() {
console.log("Hello World!");
sw();
console.log("init setWatch");
st();
console.log("start RTC");
}, 1500);
more complete comments and helper functions in attached code file
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Sun 2020.03.08
Six hours later and another peculiarity.
Adding a
setWatch();
after setup of a wired PPI group never fires.Entering
clearWatch()
will also inadvertently kill the PPI setup.Am attempting to simulate an IRQ using the following instructions:
Heading: Interrupts
'Espruino doesn't allow you to react to interrupts from these peripherals directly, however you can change the state of an external pin (see the examples above) and can then short that pin to another pin that you can use as an input with setWatch.'
Setup:
MDBT42Q breakout board with USART edge pins at 12 O'clock
D20 is an 'input' and is driven by pin D22 with a simple jumper
Watch visually the LED or hang a scope on either pin D20/D22
Execution:
After around a two second wait, a near 100Hz square wave appears on pin D20/D22
The setWatch function never executes.
Entering cw() or
clearWatch()
will also inadvertently kill the PPI setup.Some Helper functions and comments removed for brevity
1 Attachment