I want to read the signals from a transmitter,so i wrote the following code and read channel 1 correctly:
Then ι wanted to read channel 1 using PDIR register with the following code:
but i can not read the channel 1,i have made some mistake in the register pdir??
Code:
volatile byte stick_channel_1;
volatile int transmitter_channel_1;
volatile unsigned long timer_channel_1;
void transmitter_signals();
void print_signals();
void setup() {
while (!Serial);
Serial.begin(9600);
pinMode(19, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(19), transmitter_signals, CHANGE);
}
void loop() {
delay(250);
Serial.println(transmitter_channel_1);
}
void transmitter_signals() {
current_time = micros();
if (stick_channel_1 == 0 && digitalRead(19) == 1 ) {
stick_channel_1 = 1;
timer_channel_1 = current_time;
}
else if (stick_channel_1 == 1 && digitalRead(19) == 0 ) {
stick_channel_1 = 0;
transmitter_channel_1 = current_time - timer_channel_1;
}
}
Then ι wanted to read channel 1 using PDIR register with the following code:
Code:
volatile byte stick_channel_1;
volatile int transmitter_channel_1;
volatile unsigned long timer_channel_1;
void transmitter_signals();
void print_signals();
void setup() {
while (!Serial);
Serial.begin(9600);
PORTB_PCR2 = PORT_PCR_PE | PORT_PCR_PS | PORT_PCR_MUX(1); // input_pullup
GPIOB_PDDR &= ~(1 << 2); //input
attachInterrupt(digitalPinToInterrupt(19), transmitter_signals, CHANGE);
}
void loop() {
delay(250);
Serial.println(transmitter_channel_1);
}
void transmitter_signals() {
current_time = micros();
if (stick_channel_1 == 0 && [COLOR="#FF0000"]GPIOB_PDIR == (1 << 2)[/COLOR] ) {
stick_channel_1 = 1;
timer_channel_1 = current_time;
}
else if (stick_channel_1 == 1 && [COLOR="#FF0000"]GPIOB_PDIR == (0 << 2)[/COLOR]) {
stick_channel_1 = 0;
transmitter_channel_1 = current_time - timer_channel_1;
}
}
but i can not read the channel 1,i have made some mistake in the register pdir??