![diptrace 2.4 serial diptrace 2.4 serial](https://www.mdpi.com/sensors/sensors-20-05962/article_deploy/html/images/sensors-20-05962-g007.png)
Oh and in case your scan does not give you a key result, you still output the uninitialized character to UART and it may be bogus.
![diptrace 2.4 serial diptrace 2.4 serial](https://forum.mysensors.org/uploads/files/1454273529765-image2.png)
DIPTRACE 2.4 SERIAL CODE
You need to at least wait for the input syncronizer to pass the actual value for reading, and you need to wait for any capacitances to charge through any resistances (wires will have stray capacitance and compared to your fast code they will charge slowly through internal pull-ups for example). If you write to an output port to change a pin and next you read an input port, the input has not yet been updated. In case the scanning triggers more PCINT interrupts, clear pending PCINT interrupts so that there won't be another when you exit. If you do wait, wait only for the relevant bits, not the whole port! The unused bits might read 0 or 1, signals may capacitively couple between pins etc. Don't wait for key release in the interrupt. I would not put 50ms delay in an ISR (but that is discussed a number of times in the paste) Then when I have done my scans I clear the interrupt bits(very important) and re-enable the interrupts for the next key press ( I do not care about key release at this moment (not nice, but works for now))
DIPTRACE 2.4 SERIAL FULL
When handling the flag I first do a full scan to see what keys are pressed, then I use a debounce (generate second event) and if then the scan value is stil the same I know what key is pressed (did state change I scan again, until a valid scan result is there, being either a key or no key) in this interrupt I disable the keyboard interrupts and set a flag that a key is pressed(I use event system so generate an event) When you scan the rows and colums you seem to be changing the level of the rows this triggers new interrupt and as such you keep getting interrupts until you release the button as from that moment on no new interrupts can be generated.Įach column (input with pull-up) generates an interrupt. I think you made the same mistake as I did long ago. find out which button was pressed in column 4 find out which button was pressed in column 3 find out which button was pressed in column 2 find out which button was pressed in column 1 Pin change 0-7 interrupt service routine Just to add some background, I have the portB pins configured as inputs with pullups enabled, and port C configured as outputs at logic 'low' so that when a key is pressed that is what fires the interrupt. The accidental ox31 I can deal with at the moment, but I am scratching my head as to why only column one waits for the key to be released, and the other columns do not. At which time the ascii code 0x31 shows up.īut if I press any key in columns 2, 3, and 4, the key continuously transmits until I release the key, which at that time it then transmits the ascii code 0x31 as well.
![diptrace 2.4 serial diptrace 2.4 serial](http://3.bp.blogspot.com/-CclkVOiF1NY/VoN5nJfwjaI/AAAAAAAADOM/JRAWlD5Q0Q8/s1600/3.%2BDiptrace%2BFull%2BVersion%2BTerbaru%2Bwww.faidishare.com.jpg)
Meaning, if I press a key in column one and hold it down, the AVR will transmit it's value to the terminal and wait for me to release the key. The problem is that with the exception of column 1 the key just keeps repeating itself in the terminal window until I release the key. This is working somewhat, the key pressed does indeed show up in my terminal program, along with the ascii code for the number '1' which is another story, but is acceptable. I am using pinchange interrupt to signal that a button has been pressed, then in the interrupt routine I scan the keypad to see which key was pressed then send the key character to the usart. I have a 4 column x 5 row keypad connected to my Mega48.