PiBrewing / craftbeerpi4

GNU General Public License v3.0
57 stars 29 forks source link

"CS pin already used. Must be exclusive!" ADS1256 SPI communication #115

Closed mjiao5151 closed 1 year ago

mjiao5151 commented 1 year ago

Try to write a plugin to read analog signals with the help of an ADS1256 ADC module. the ADC module has 8 analog inputs, and communicates with rpi via SPI bus. the plugin works fine with only one AI channel configured in cbpi4, but will report error when additional channels were configured. the error message was "CS pin already used. Must be exclusive!"

I am wondering what is the cause of this issue, any help will be greatly appreciated! thansk!

prash3r commented 1 year ago

from this information alone i would guess your implementation results in every configured channel to try and manage the SPI bus itself. the first channel creates the SPI bus, acts as a SPI bus master and works fine and the second channel also tries to create the SPI bus on the same cbpi pins but cant because they are of course already in use by the other channel as all the channels should be running via the same SPI bus.

there are multiple ways to implement this but the important thing is that the channels need to use the same SPI BUS and not try to create one each.

I wasnt able to find the repo you are talking about. Maybe your repo is private or offline? If you want me to have a look make it available and link it here.

I will soon close this issue as it has nothing to do with the main repo. There soon will be proper channels for requesting plugin dev support from the community.

mjiao5151 commented 1 year ago

Dear prash3r Thank you for your quick reply. I pushed my code to github. please see here https://github.com/mjiao5151/cbpi4_analog_sensor

my code is modified from https://github.com/sjhoglund/cbpi4-PressureSensor the ads1256 wrapper was from https://github.com/ul-gh/PiPyADC

thanks!

mjiao5151 commented 1 year ago

Dear prash3r good news, I got my code working. I followed the main idea you point out, and worked based on the structure of the plugin cbpi4-scd30-CO2-Sensor . with one class reading the signal and store the data in a global variable, each cbpi sensor only read the cached data. Which got it working. Thank you again for pointing out the problem!

Best Regards!

avollkopf commented 1 year ago

Great, this would have been also my suggestion (scd30-CO2-Sensor). Activate the chip with the cbpi extension once and add up to 8 sensors via the sensor plugin. A similar actor example could be also this one: https://github.com/PiBrewing/cbpi4-PCF8574-GPIO.

EDIT: If it is working, please close the issue here