Mikrocontroller und Digitale Elektronik
›
Thread
Hilfe bei AVR PCINT
RB
R. B.
(dxx255)
OP
04.09.2014 23:00
#3790809
Hallo
Ich möchte mit einem Attiny 85 den PCINT des Reset Pins nutzen. Die
Fuses hab ich entsprechend gesetzt. Hier der Code: 1 #include <avr/io.h>
2 #include "nrf24.h"
3 #define F_CPU 1000000L
4 #include <util/delay.h>
5 #include <avr/interrupt.h>
6 uint8_t tx_address [ 5 ] = { 0xE7 , 0xE7 , 0xE7 , 0xE7 , 0xE7 };
7 uint8_t messages [ 2 ][ 8 ] = {{ 0 , 0 , 126 , 126 , 126 , 0 , 0 },{ 0 , 0 , 127 , 127 , 127 , 0 , 0 }}; //opened closed
8 int main () {
9 nrf24_init ();
10 PCMSK |= ( 1 << 5 );
11 GIMSK |= ( 1 << 5 );
12 DDRB &= ~ ( 1 << 5 );
13 PORTB |= ( 1 << 5 );
14 /* Channel #2 , payload length: 8 */
15 nrf24_config ( 2 , 8 );
16
17 /* Set the device addresses */
18 nrf24_tx_address ( tx_address );
19 sei ();
20 while ( 1 ) {
21 }
22
23 return 0 ;
24 }
25 ISR ( PCINT0_vect ){
26 _delay_ms ( 50 );
27 nrf24_send ( messages [( PINB & ( 1 << 5 )) >> 5 ]);
28 while ( nrf24_isSending ());
29 }
Wenn ich aber PB5 an Masse lege wird die ISR immer doppelt ausgeführt.
Wenn ich die Verbindung wieder trenne nicht. Warum ist das so?
LG
MV
Marc V.
(logarithmus)
(Firma: Vescomp)
04.09.2014 23:18
#3790835
Roman B. schrieb:
> Wenn ich aber PB5 an Masse lege wird die ISR immer doppelt ausgeführt.
> Wenn ich die Verbindung wieder trenne nicht. Warum ist das so?
Welche Verbindung ? Zur Masse oder zu anderem NRF ?
Und wie meinst du das: "PB5 an Masse lege " ?
RB
R. B.
(dxx255)
OP
04.09.2014 23:22
#3790839
PB5 ist über einen Reed-Schalter mit GND verbunden. Wenn ich den auslöse
werden zwei Nachrichten versandt. Wenn ich ihn loslasse nur eine. Warum?
Wird wohl am prellen liegen.
MV
Marc V.
(logarithmus)
(Firma: Vescomp)
04.09.2014 23:28
#3790846
Roman B. schrieb:
> werden zwei Nachrichten versandt. Wenn ich ihn loslasse nur eine. Warum?
Prellen ?
Weil das zweite Ereignis gespeichert wir, während die erste ISR noch
läuft.
Beim Loslassen hast du wohl tatsächlich nur eine einzige Flanke, gut
möglich.
Deine ISR ist an sich Mist, mit delay und zeitaufwändiger Kommunikation.
Kannst ja als erste Massnahme erstmal vor Verlassen der ISR weitere
anhängige Pinchange-Ints löschen, dann wirds funktionieren. Ist aber
bestimmt noch nicht die endgültige Lösung :-)
RB
R. B.
(dxx255)
OP
04.09.2014 23:57
#3790874
So gehts: 1 #include <avr/io.h>
2 #include "nrf24.h"
3 #define F_CPU 1000000L
4 #include <util/delay.h>
5 #include <avr/interrupt.h>
6 uint8_t tx_address [ 5 ] = { 0xE7 , 0xE7 , 0xE7 , 0xE7 , 0xE7 };
7 uint8_t messages [ 2 ][ 8 ] = {{ 0 , 0 , 126 , 126 , 126 , 0 , 0 },{ 0 , 0 , 127 , 127 , 127 , 0 , 0 }}; //opened closed
8 char state =- 1 ;
9 int main () {
10 nrf24_init ();
11 PCMSK |= ( 1 << 5 );
12 GIMSK |= ( 1 << 5 );
13 DDRB &= ~ ( 1 << 5 );
14 PORTB |= ( 1 << 5 );
15 /* Channel #2 , payload length: 8 */
16 nrf24_config ( 2 , 8 );
17
18 /* Set the device addresses */
19 nrf24_tx_address ( tx_address );
20 sei ();
21 while ( 1 ) {
22 if ( state ){
23 cli ();
24 nrf24_send ( messages [ state - 1 ]);
25 while ( nrf24_isSending ());
26 state =- 1 ;
27 sei ();
28 }
29 }
30
31 return 0 ;
32 }
33 ISR ( PCINT0_vect ){
34 _delay_ms ( 50 );
35 state = ( PINB & ( 1 << 5 ) >> 5 ) + 1 ;
36 }
Durch die Brust ins Auge?
RB
R. B.
(dxx255)
OP
05.09.2014 00:09
#3790884
Was meinst du damit? Es geht doch nicht:(
RB
R. B.
(dxx255)
OP
05.09.2014 00:22
#3790893
Jetzt aber: 1 #include <avr/io.h>
2 #include "nrf24.h"
3 #define F_CPU 1000000L
4 #include <util/delay.h>
5 #include <avr/interrupt.h>
6 uint8_t tx_address [ 5 ] = { 0xE7 , 0xE7 , 0xE7 , 0xE7 , 0xE7 };
7 uint8_t messages [ 2 ][ 8 ] = {{ 0 , 0 , 126 , 126 , 126 , 0 , 0 },{ 0 , 0 , 127 , 127 , 127 , 0 , 0 }}; //opened closed
8 int state =- 1 ;
9 int main () {
10 nrf24_init ();
11 PCMSK |= ( 1 << 5 );
12 GIMSK |= ( 1 << 5 );
13 DDRB &= ~ ( 1 << 5 );
14 PORTB |= ( 1 << 5 );
15 /* Channel #2 , payload length: 8 */
16 nrf24_config ( 2 , 8 );
17
18 /* Set the device addresses */
19 nrf24_tx_address ( tx_address );
20 sei ();
21 while ( 1 ) {
22 if ( state ){
23 cli ();
24 nrf24_send ( messages [ state - 1 ]);
25 while ( nrf24_isSending ());
26 state =- 1 ;
27 sei ();
28 }
29 }
30
31 return 0 ;
32 }
33 ISR ( PCINT0_vect ){
34 _delay_ms ( 50 );
35 if ( PINB & ( 1 << 5 )) state = 1 ;
36 else state = 2 ;
37 }
Antwort schreiben
Bitte melde dich an, um einen Beitrag zu schreiben.
Noch kein Account?
Die Registrierung ist kostenlos und dauert nur eine Minute.
Jetzt registrieren