wollewald / ADS1220_WE

Arduino library for the 24-bit, 4 channel ADS1220 ADC
https://wolles-elektronikkiste.de/en/
MIT License
20 stars 2 forks source link

”ADS1220_WE“ usage #1

Closed xiyangdiy closed 2 years ago

xiyangdiy commented 2 years ago

How to use "SPIClass s" in ADS1220_WE(int cs, int drdy, SPIClass s), I would be grateful if you could tell me

wollewald commented 2 years ago

Hi @xiyangdiy,

there two ways to create your ADS1220 object:

ADS1220_WE ads = ADS1220_WE(ADS1220_CS_PIN, ADS1220_DRDY_PIN);
// or:
ADS1220_WE ads = ADS1220_WE(ADS1220_CS_PIN, ADS1220_DRDY_PIN, &SPI);

The second option uses "SPIClass *s". If you work with just one SPI object, then it doesn't make a difference which option you take. The SPI object is passed as a reference (with the "&"). That means the original object is used. So it's not too interesting for MCUs which only have one SPI interface. But if you work for example with an ESP32 which has two SPI interfaces and you want to use both then you would need to pass the SPI objects.

wollewald commented 2 years ago

By the way thanks for the first star! And sorry for all the releases with the last weeks. Since it is new, I still found some bugs.

xiyangdiy commented 2 years ago

Thank you for your answer. Can this library use SoftSPI? If so, do you have a specific example? I found a library, its name is "SoftSPIB", it can customize spi pins, but I don't know how to use it with "ADS1220_WE" library.

xiyangdiy commented 2 years ago

My MCU is ESP32-S3.

wollewald commented 2 years ago

That would need some changes in the library. You would define the SoftSPIB Object like this:

SoftSPIB mySPI(12, 13, 4);

and then pass the mySPI object like this:

ADS1220_WE ads = ADS1220_WE(ADS1220_CS_PIN, ADS1220_DRDY_PIN, &mySPI); 

On the library side you would need a constructor that takes the SoftSPIB object, like:

ADS1220_WE::ADS1220_WE(int cs, int drdy, SoftSPIB *s){
     _softSPI = s;

A variable would need to be defined:

SoftSPI *_softSPI;

And then finally all SPI functions (line 324 till the end) in ADS1220_WE.cpp would need to be changed to the corresponding SoftSPIB functions, beauce they are a bit different.

So in summary: the library could be adjusted, but with some effort.

If may ask why do you want to use SoftSPIB? Why don't you just use the standard SPI interface of the ESP32?

wollewald commented 2 years ago

I have just tried an example sketch with an ESP32 Development Board using the standard SPI interface. I only had to adjust the DRDY Pin and the CS Pin. The rest was unchanged.

xiyangdiy commented 2 years ago

Thanks for your enthusiastic answer! I'm just a beginner, your answer helped me a lot!

wollewald commented 2 years ago

You are welcome!