Where I can find some examples on AD7738 (connection, analog input reading)?
One thing I noticed is that there’s no monitoring condition for the /RDY in your code. When 0x38 is written to the Mode Register, the /RDY pin goes high and the ADC starts the conversion on the channel selected. When /RDY line goes low, this indicates that conversion is complete and a new data is available. This conversion time corresponds to what is written to the channel conversion time register which is conversion time (us) = (FW x 128 + 248)/MCLK. The equivalent FW you wrote to the time register is 17 decimal, so if you have an MCLK = 6.144 MHz then the conversion time is roughly 395 us which can also be found in Table 1 on Page 9 of the datasheet.
After the /RDY line goes low, this is the right time to read the data by writing 0x4F.Since you have enabled the continuous conversion in the Channel Setup Register and the DUMP bit in the Mode Register, the Channel Status read is followed by a read of the Data Register. Note that the /RDY line will go high after the Status Register is read. After the Data register is read, the /RDY line will continue to go high until another conversion is complete and then write 0x4F again. This process will continue until you write something new to the Mode Register.
The continuous read can be enabled by setting the CONT RD bit in the MODE Register so there is no need to write 0x4F again once the /RDY goes low after the first conversion.
Finally, I will be sending an offline mail for the example code later. Please take note that the code is not using the device you are asking but still came from the same family.
Please let us know if this will fix the problem.
I suggest that you take a look the schematic of its evaluation board. You need to install the software first which can be downloaded here (http://www.analog.com/en/evaluation/EVAL-AD7734/eb.html). The documentation/schematic can be found in the directory to where the program is installed.
Let us know if you still need assistance.
But I don't have an evaluation board. I have AD7738 connected to my microcontroller and I thought maybe there is some examples of connecting/reading data via SPI on various p.languages? I'm having some trouble with reading data from my sensor with the micro controller (sensor is connected to AIN7).
I would appreciate if you point me what is wrong with my code.
Here is what I'm doing:
SPI_SendData8(SPI, 0b00000001); //IO port register, write
SPI_SendData8(SPI, 0b11110000); //Configure IO port register
SPI_SendData8(SPI, 0b00101111); //Channel setup register, AIN7, write
SPI_SendData8(SPI, 0b00011100); //Configure Channel setup register
SPI_SendData8(SPI, 0b00110111); //Channel conversion time register, AIN7, write
SPI_SendData8(SPI, 0b10010001); //Std. value
SPI_SendData8(SPI, 0b00111111); //Mode register, write (0x3F)
SPI_SendData8(SPI, 0b00111000); //Continuous conversion, no clamp (0x38)
Next I send 0x4F in a cycle and receive 16 bit values. But this value is always 0.
What am I doing wrong?
Ah, apparently I configured SPI wrong. But anyway am I doing everything right?
I keep receiving the default value (0x8000) instead of channel data. RDY goes low just as intended, I send 0x4F and then (0x00 0x00) but I receive only (0x80 0x00) despite I changed my sensor value. Is there any condition when you receive the default value?
I tried writing 0x4F in a cycle (when RDY goes low ofc) and I get 0x8000, next 0x80, next 0x00, next again 0x8000 etc. I noticed that when I turn off the power of my sensor, the value I mentioned before (0x8000, 0x80, 0x00,) changes to (0xE080, 0xE0, 0x8000), that's strange :|
Also what about the connection settings?
According to figure 1 and figure 2, CPOL=1 and CPHA=1. I assume my controller should be Master, Data size should be 8 bit, MSB is the first bit. There is also baud rate control parameter for master: Fbaud = Fpclk / (2^(BR+1)). BR can be 2 to 256. Now I have BR = 4.
Settings are described here on page 18: http://www.eng.auburn.edu/~nelson/courses/elec5260_6260/SPI%20STM32.pdf
First of all, how the Mode Register is configured? Second, how the data is read - did you put the DIN low?
If 0x48 is written on the Mode Register, the ADC is set in Single Conversion Mode, Dump Mode, 16-Bit Data and No Clamp Mode (refer to Figure 8 in page 21 of the datasheet). When the DRDY goes low, writing 0x4F to the communications register tells that the next operation is a read of data in channel number 0x7 in the data address 0xF. Upon reading, DIN line should not be high. Since Dump Mode is set, the Channel Status Register is read first then the Data Register. Channel Status Register is read by writing 0x00 to the communications register. You can check which channel is being converted with this data. Try also to check if there's overrange on the inputs by looking the value of the OVR bit. The Channel Status Register is being discussed on Page 16 of the datasheet. The read to the data register will follow by taking DIN low again. Data register is being set to 16-bit therefore apply 2 writes of 0x00 to the communications register.
Try to do this and tell us the results.
//edit: I forgot to turn on my sensor
Retrieving data ...