Page 1 of 1

Repeated communication with 2 SPI slaves

Posted: Fri Apr 29, 2016 3:17 pm
by danielm
In my laser 3d printer controller project I need to communicate with 2 SPI slaves repeatedly. The problem is that both slaves are using different polarity and phase settings. Is there any way how to re-configure existing SPI object? Does spi.init() do this? Or is the only solution to create new SPI object with different settings over and over?

Re: Repeated communication with 2 SPI slaves

Posted: Fri Apr 29, 2016 3:26 pm
by danicampora
Wow, a laser 3D printer? Sounds like a very cool project :-)

The answer is to use spi.init(). Good luck!

Cheers,
Daniel

Re: Repeated communication with 2 SPI slaves

Posted: Fri Apr 29, 2016 4:49 pm
by danielm
Thanks, I will try that.

You can find more info regarding our project here: http://marsaltech.com/
I will update news section in next few days :)

Re: Repeated communication with 2 SPI slaves

Posted: Sat Apr 30, 2016 1:20 pm
by danielm
Daniel, I have another issues, hope you can help me :)

1. In main.py I create objectA as an instance of classA. This object represents one of HW modules of my controller.
2. Then I create objectB as an instance of classB. This object represents client to my backend server service.
3. By calling objectB.functionB() I want to start processing of some data loaded from a file and based on this data perform some actions on HW module by calling objectA.functionA().

The problem is that from "inside" of instantiated classB as objectB the object objectA is not "visible" (name not defined). Should I pass objectA (and all other objects representing HW resources) as parameters when creating objectB? Or are there any other solutions?

Re: Repeated communication with 2 SPI slaves

Posted: Sat Apr 30, 2016 7:18 pm
by SpotlightKid
danielm wrote:Should I pass objectA (and all other objects representing HW resources) as parameters when creating objectB?
Either that, e.g. by making it an argument to the constructor of ClassB or by having an attribute/property on the ClassB instance, which you set to the ClassA instance after instantiation of objectB, or you put both instances, objectA and objectB, in the same namespace, usually either the global one, or that of your main() function.

See also:

https://en.wikipedia.org/wiki/Design_Patterns

and

http://c2.com/cgi/wiki?CategoryStructuralPatterns


Chris

Re: Repeated communication with 2 SPI slaves

Posted: Sun May 01, 2016 12:23 pm
by danielm
Chris, thank you for your answer ;-)