Reading DIN0

Universal Programmable Converter for CAN FD and CAN
Post Reply
EmilB
Posts: 3
Joined: Thu 19. Dec 2024, 12:35

Reading DIN0

Post by EmilB » Fri 20. Dec 2024, 13:52

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

M.Heidemann
Sales & Support
Sales & Support
Posts: 1072
Joined: Fri 20. Sep 2019, 13:31

Re: Reading DIN0

Post by M.Heidemann » Fri 20. Dec 2024, 15:49

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
---
Marvin Heidemann
PEAK-Support Team

EmilB
Posts: 3
Joined: Thu 19. Dec 2024, 12:35

Re: Reading DIN0

Post by EmilB » Wed 8. Jan 2025, 12:51

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

EmilB
Posts: 3
Joined: Thu 19. Dec 2024, 12:35

Re: Reading DIN0

Post by EmilB » Wed 8. Jan 2025, 14:49

Solved

The cabling was the problem, it was always tied to ground. After fixing cabling then works as intended.

//Emil

M.Heidemann
Sales & Support
Sales & Support
Posts: 1072
Joined: Fri 20. Sep 2019, 13:31

Re: Reading DIN0

Post by M.Heidemann » Wed 8. Jan 2025, 16:51

Hello Emil,

Thank you for letting us know!

BR

marvin
---
Marvin Heidemann
PEAK-Support Team

Post Reply