Jump to content

FIXED: Can't get MIOS32_BOARD_J5_PinGet() to work


Sam_K
 Share

Recommended Posts

I am developing a MIOS32 app and I've run into a bit of a problem.

When I try to use MIOS32_BOARD_J5_PinGet() it always returns zero, however if I check the same pin in the APP_AIN_NotifyChange() hook the hook does get called with changes of input and the value provided to the hook is correct.

Attached is a minimumal app to demonstrate the problem. If you compile and run this app as is then you should see just "0000" in the top left of the LCD screen which does not change in response to analogue values at pin 0.

If you look at APP_AIN_NotifyChange() in app.c you will see there is two versions of the line that prints the value of pin 0 to the LCD. One line simply prints "pin_value" (this one is commented out) and the other line re-fetches the value using MIOS32_BOARD_J5_PinGet(0). When "pin_value" is printed, the correct value is shown (changing value between 0 and 4096), but when the value from MIOS32_BOARD_J5_PinGet() is printed, it always comes out as 0000.

From my reading of things, both of these lines should produce exactly the same result.

What am I doing wrong?

j5_test.zip

Edited by Sam_K
Link to comment
Share on other sites

I went and looked at the code for MIOS_BOARD_J5_PinGet() in mios32/STM32F10x/mios32_board.c and I learned 2 things.

Firstly I need to set a #define for J5_NUM_PINS before PinGet will work. I put this into my mios32_config.h file as a line that reads "#define J5_NUM_PINS 6". Is that correct?

EDIT: I now see that J5_NUM_PINS is #defined to 12 elsewhere in mios32_board.c

Secondly, the last line of MIOS_BOARD_J5_PinGet() looks like this:


return (j5_pin[pin].port->IDR & j5_pin[pin].pin_mask) ? 1 : 0;

Now, I'm no C expert, but my interpretation of that line of code is that it could only ever return a 1 or a 0, but I am expecting this function to return a value between 0 and 4096!

Confused....

Edited by Sam_K
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...