-
|
I'd like to extend diozero to work with this Raspberry Hat. It has a standard SPI pin assignment except for cs which is BCM 22. I'm fairly comfortable programming in Java but not an expert. Could someone give me an idea where to start. I expect I need to define a class for the device implementing the MpcAdc interface. Is there an existing class I could mimic/copy/modify? Any help would be appreciated. I scanned the core source code and have a rough idea but would rather not go down the wrong path. |
Beta Was this translation helpful? Give feedback.
Replies: 12 comments 2 replies
-
|
Hi. The ADS112C04 and the simpler ADS1015 / ADS1115 would be good references. My starting points would always be the datasheet along with existing implementations for reference, e.g. this one. |
Beta Was this translation helpful? Give feedback.
-
|
Those two devices hace I2C interfaces. The ADS1263 has an SPI interface. Are there any SPI interface devices in the library? |
Beta Was this translation helpful? Give feedback.
-
|
Yes, there are also a few devices that support both SPI and I2C, e.g. MCP23x17, BMx280, the SSD OLEDs. |
Beta Was this translation helpful? Give feedback.
-
|
I did a tiny test and got a failure. If you see the problem, please let me know what's wrong. I suspect I'm not creating spi properly. Output |
Beta Was this translation helpful? Give feedback.
-
|
I also tried initializing spi with this but same problem
|
Beta Was this translation helpful? Give feedback.
-
|
The following does not cause an error but the bytes returned are both 0; It should be non xero the chipID. The second argument is supposed to be the BCM chip select pin so maybe because it 0, the write is not even attempted. output |
Beta Was this translation helpful? Give feedback.
-
|
OK, I realized I had forgotten to enable chip select before spi.write. It still results in the same error but here is my current simple code. Output |
Beta Was this translation helpful? Give feedback.
-
|
In NativeSpiDevice the statement This explains why So the chipSelect arg is improperly named. I think it probably should be port number. I still get 0x00, 0x00 as a response which is incorrect |
Beta Was this translation helpful? Give feedback.
-
|
I understand the confusion - you assumed you needed to pass the BCM GPIO number for the chip select pin. The API naming in diozero was based on a standard definition of a SPI device:
diozero delegates all SPI control to the kernel - hence diozero is oblivious to SPI device physical CS / MOSI / MISO / SCLK pins. I can review the API Javadoc to make this clearer. |
Beta Was this translation helpful? Give feedback.
-
|
Well now that that's sorted out, I'm able to write and read from the SPI port. Now it's up to me to figure out what's wrong with my protocol. |
Beta Was this translation helpful? Give feedback.
-
|
FYI, After much digging, it works!. I had taken an ADS1263 python demo program and used S/W Architect GPT to translate to java. Never expected it to work but save a lot of time with constant definition etc. The key problem was that I was also getting a 0x00 on a data read. Turns out my method to ask for data was writing to the wrong register. After that everything fell into place. I noticed in the link https://en.wikipedia.org/wiki/Serial_Peripheral_Interface is calls the spi chip select Slave Select (SS). I'm naming it as such in my code. |
Beta Was this translation helpful? Give feedback.
-
|
So here is my ADS1263 demo project using diozero. It is a Netbeans Maven project. |
Beta Was this translation helpful? Give feedback.
Well now that that's sorted out, I'm able to write and read from the SPI port. Now it's up to me to figure out what's wrong with my protocol.