Reading DIN0
Reading DIN0
Hello!
Trying to read the DIN0 with the PCAN-Router FD with the following code.
// variable for storing Digital Input
uint32_t diStatus = 0;
In int main function
// check digital input and send out status on CAN
HW_GetDIN ( &diStatus );
din0 = (diStatus >> 0) & 1;
This always gives me a zero on the input even though I measure 0 and 12 V on the pin 8 of the CAN2 D-sub.
Two questions, is pin 8 the correct input of DIN0 and is also necessary to have power on pin 9 and GND on Pin 3 on CAN2 input to be able to read the DIN0 input pin?
Regards Emil
Trying to read the DIN0 with the PCAN-Router FD with the following code.
// variable for storing Digital Input
uint32_t diStatus = 0;
In int main function
// check digital input and send out status on CAN
HW_GetDIN ( &diStatus );
din0 = (diStatus >> 0) & 1;
This always gives me a zero on the input even though I measure 0 and 12 V on the pin 8 of the CAN2 D-sub.
Two questions, is pin 8 the correct input of DIN0 and is also necessary to have power on pin 9 and GND on Pin 3 on CAN2 input to be able to read the DIN0 input pin?
Regards Emil
-
- Sales & Support
- Posts: 1072
- Joined: Fri 20. Sep 2019, 13:31
Re: Reading DIN0
Hello,
If i am not completely mistaken you are assigning DinStatus which you set to 0 to Din0,
then you would come up 0 every time regardless of what the input actually reads...
Am i misunderstanding what you are doing here?
BR
Marvin
If i am not completely mistaken you are assigning DinStatus which you set to 0 to Din0,
then you would come up 0 every time regardless of what the input actually reads...
Am i misunderstanding what you are doing here?
BR
Marvin
---
Marvin Heidemann
PEAK-Support Team
Marvin Heidemann
PEAK-Support Team
Re: Reading DIN0
Hi!
Have had winter holidays now back to this problem.
I'm assigning diStatus to zero at initialization, then in the while loop HW_GetDIN is called and address of diStatus is sent as an argument to the HW_GetDIN function.
This to me should give me the current status of DIN into the value of variable diStatus.
Then din0 is given status of bit 0 of diStatus that should be status of DIN0. But this is always 0.
If I do not perform the bit-wise check on diStatus it is read as decimal 6 but it never changes if I switch the switch on DIN0 input.
Can you confirm that DIN0 input pin is PIN8 in the DSUB 2 on the PCAN-Router FD.
And I used a 10 kohm resistor between pin 9 and pin 8 and the switch is between pin 9 and pin 3.
Is this setup correct?
Regards Emil
Have had winter holidays now back to this problem.
I'm assigning diStatus to zero at initialization, then in the while loop HW_GetDIN is called and address of diStatus is sent as an argument to the HW_GetDIN function.
This to me should give me the current status of DIN into the value of variable diStatus.
Then din0 is given status of bit 0 of diStatus that should be status of DIN0. But this is always 0.
If I do not perform the bit-wise check on diStatus it is read as decimal 6 but it never changes if I switch the switch on DIN0 input.
Can you confirm that DIN0 input pin is PIN8 in the DSUB 2 on the PCAN-Router FD.
And I used a 10 kohm resistor between pin 9 and pin 8 and the switch is between pin 9 and pin 3.
Is this setup correct?
Regards Emil
Re: Reading DIN0
Solved
The cabling was the problem, it was always tied to ground. After fixing cabling then works as intended.
//Emil
The cabling was the problem, it was always tied to ground. After fixing cabling then works as intended.
//Emil
-
- Sales & Support
- Posts: 1072
- Joined: Fri 20. Sep 2019, 13:31
Re: Reading DIN0
Hello Emil,
Thank you for letting us know!
BR
marvin
Thank you for letting us know!
BR
marvin
---
Marvin Heidemann
PEAK-Support Team
Marvin Heidemann
PEAK-Support Team