Support Forum

Share your projects and post your questions

Register   or   Sign In
The Forum

multiple IO Pi Plus using C libraries

2447 Views - Created 27/02/2016

27/02/2016

Posted by:
Boy

Boy Avatar

Hi,I think I've found a bug in the C library last year, I think it is time to get it confirmed.I am using the Pi with 2 boards. While using it, I found out that wierd stuff was happening: bits were toggling on the order board, while handeling commands to the other.Diving into the code, I found in IOPi/ABE_IoPi.c that the variables portaval and portbval (and others) are NOT per board. So when I change a value for board (e.g. at address 0x21), this value will also be written to a different board (e.g. at address 0x27)!I've made a quick fix and made arrays of portaval, portbval, etc, so each board has its own variable.I didn't see th problem anymore after this. Am I overlooking something?What I still see actually, is that sometimes when toggling an input, it seems to give a side-effect and toggle another output pin. I have to debug this further, probably has nothing to do with your board. But if it does and you might have an idea, I would love to here about a workaround/fix! Regards,Boy

27/02/2016

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

Hi

Thank you for finding the bug with the C library. I have changed the way the library works so instead of using variables it now reads the register values from the IO Pi before updating them which should hopefully fix the problems with running multiple IO Pi Plus boards on the same Raspberry Pi.

I have uploaded a new version to GitHub https://github.com/abelectronicsuk/ABElectronics_C_Libraries/blob/master/IOPi/ABE_IoPi.c

28/02/2016

Posted by:
Boy

Boy Avatar

Hi Andrew,Thanks a lot for your very fast response and fix! I checked your change and indeed this should work OK. I will test your version soon. I cannot just make a change as the system is in production at the moment (it is used in an Escape Room).

28/02/2016

Posted by:
Boy

Boy Avatar

28/02/2016

Posted by:
Boy

Boy Avatar

Hi Andrew,I was hoping to also find something for the phenomena that sometimes when a bit is toggled, another bit is toggled too (input, or output, doesn't matter I think).I am really a software developer. My hardware knowledge is limited. Maybe it could be something to do with pullups/pulldowns? I don't know. Maybe you can point me in some direction.

29/02/2016

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

Pullups and pull-downs should only be needed on an input to stop the pin from toggling between states, it should not have any effect on other pins. You normally use a pull-up resistor when the input is going to be pulling the voltage low and a pull-down when the voltage is going to be going high. The pull-up and pull-down resistors stop the pin from being in a floating state where the internal capacitance could cause he input to be read as high or low. The internal pullup resistors should be disabled when using a pin as an output.

The function that changes the state of the individual bits is the same one I have used on the other C libraries and I have not seen any problems with the wrong bit being set so I don't think it is related to that function.

The most likely cause for the bug is probably where the library was using the shared variables for all of the pin directions and states so hopefully now the library is reading the value from the chip before changing a bit it should behave itself.

Sign in to post your reply

Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view.
Download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.