just made library for AD5321 digital potentiometer
I am able to send commands and get potentiometer to change (A-W-B)
I am able to track and print that all commands are sent as required
I am not able to get the right response from reading command
it just not returning the values but just keep repeating the request
from who of you interested or have some background with this device
attached is the code with example problem
_write sent 33 1 2 get B0 0 9 // sending writ to EEROM address 3, value 102 geting last change potentiometer command - OK
_write sent 93 0 0 get 33 1 2 // asking to read from EEROM addres 3, geting last command - OK
_write sent 0 0 0 get 93 0 0 // sending NOP but getting the last command and not EEROM value, should be 93 1 2 - ERROR
remarks: ignore file names AD5325, it was made for AD5321
AD5235.pde (1002 Bytes)
AD5235.cpp (4.98 KB)
AD5235.h (1.65 KB)
The cpp code can be made a bit more neat by using your own defined functions:
byte AD5235::restoreRdac(byte nDac, int value)
_write( RESTORE_EEMEM_TO_RDAC_COMMAND, nDac, 0); <<< should the 0 be value?
It is not clear in this function why it has the parameter value.
Normally I build such a library in 3 layers to keep it maintainable.
- Class public layer - These are to be called you the user of the lib
- Class private layer - these are helpers to implement the public methods
- Hardware abstraction layar
3) is the only place that contains IO with the hardware e.g. read/writes on pins etc, so if there is a change in the HW you only need to change it there
2) keeps the inner logic of the class hidden for the user
- makes the class usable.
The above function would then be written as
public byte AD5235::restoreRdac(byte nDac, value)
command( RESTORE_EEMEM_TO_RDAC_COMMAND, nDac, 0);
// HAL LAYER
private byte AD5235::command(...) ...
private byte AD5235::enable() ...
private byte AD5235::disable() ...
command is a wrapper around the _write of course.
my 2 cents