Hello again, I am currently trying to use the ADC MCP3903 in conjunction with the feather M0.
I am using kerrydwong's library GitHub - kerrydwong/MCP3903: Arduino Library for MCP3903 and it is working to the point that I can read out data from it. However, I would like to use an external reference value which
is given in the datasheet as VREFEXT=1 .
The problem is that I have little understanding on where to look in the datasheet and how to change the library correctly to communicate with the ADC. Could you please tell me how to do so? an example would be verty much appreciated.
Unfortunatly that is my problem. I do not know how to find and/or write to the registry of the ADC. I have not changed anything of the code shown on github.
A quick look at the library's source code shows that it provides the methods:
unsigned long readRegister(byte reg);
void writeRegister(byte reg, unsigned long data);
Without digging in too deeply, I’d conjecture that they provide direct reading and writing of the device’s registers. If so, then your job is to pour over the datasheet until you figure out what registers need to be set in order to provide the functionality you want.
Some device datasheets are really good and easy to figure out. Some are crap. But, that’s what you got to do.
gfvalvo:
A quick look at the library's source code shows that it provides the methods:
unsigned long readRegister(byte reg);
void writeRegister(byte reg, unsigned long data);
Without digging in too deeply, I’d conjecture that they provide direct reading and writing of the device’s registers. If so, then your job is to pour over the datasheet until you figure out what registers need to be set in order to provide the functionality you want.
Some device datasheets are really good and easy to figure out. Some are crap. But, that’s what you got to do.
That is what I am trying to do. However this is the first time that I am doing this and I am rather confused to be honest. What I am trying is to compare the datasheet (http://ww1.microchip.com/downloads/en/DeviceDoc/25048B.pdf) to the already written library to see if I can make sense of it but I am not sure what to look for.
See Page 44 of the datasheet. The Configuration Register is at address 0x0A. The library defines a constant for you to use:
static const byte REG_CONFIG = 0x0A;
The EXTVREF field is Bit 1 of this register.
Looking at the Example and Library code, this register is only written in the reset() method.
Rather than modifying the library, I’d let it set things up using the reset() method. Then do a readRegister() to retrieve the Config Reg, modify the bit(s) you want, then do writeRegister() to write it back. You need to read the datasheet as this may require multiple writes in order to provide the proper sequence. Between that and the Library source code, there seems to be enough info for you to take an initial crack at this.