Problems on reading/writing through I2C
Hi all,
I have been trying to communicate through I2C with the following ADC:
http://cds.linear.com/docs/en/datasheet/2493fe.pdf
I have been developing an Android Application in order to read the 4 output bytes of the ADC conversion but is not reading anything. This ADC is particularly different because it doesn’t have any registers to read. Just send some commands or bytes of info and it will do the conversion. Here it would be the execution of the Android application code:
My program, as it is referred in the datasheet, it has to send 2 8-bit word information. The first to select the channel and the operation mode of it (differential in this case) and the second one selects the conversion parameters. The first parameter to write is the 7-bit device address as we put CA1 and CA0 HIGH in the board, it is 0x34 or 0110100 (page 19 of the datasheet). The second parameter would be the register address and as the ADC doesn’t have any like that, I put is 0x00. And the 3rd parameter is the word/data to be sent for selecting the differential channel CH0-CH1 and, the second word the conversion parameters (pages 16 and 17). In addition, the first word has to have two preamble bits and one enable bit and in order to work, they should be 101.
Then we read the 32bits/4bytes of the conversion:
idea what would be the problem?
Thanks anyway.
I have been trying to communicate through I2C with the following ADC:
http://cds.linear.com/docs/en/datasheet/2493fe.pdf
I have been developing an Android Application in order to read the 4 output bytes of the ADC conversion but is not reading anything. This ADC is particularly different because it doesn’t have any registers to read. Just send some commands or bytes of info and it will do the conversion. Here it would be the execution of the Android application code:
My program, as it is referred in the datasheet, it has to send 2 8-bit word information. The first to select the channel and the operation mode of it (differential in this case) and the second one selects the conversion parameters. The first parameter to write is the 7-bit device address as we put CA1 and CA0 HIGH in the board, it is 0x34 or 0110100 (page 19 of the datasheet). The second parameter would be the register address and as the ADC doesn’t have any like that, I put is 0x00. And the 3rd parameter is the word/data to be sent for selecting the differential channel CH0-CH1 and, the second word the conversion parameters (pages 16 and 17). In addition, the first word has to have two preamble bits and one enable bit and in order to work, they should be 101.
i2cModule.writeData((byte) 0x34, (byte) 0x00, new byte[]{(byte) 0xA0}); //Preamble and Enable bits (101) with Channel CH0-CH1 and differential mode selected (00000)Then my program waits 100ms for the conversion to be completed. In the datasheet for the speed mode and the filter selected above would be around 80ms but I put 100ms just in case (page 5 of the datasheet).
i2cModule.writeData((byte) 0x34, (byte) 0x00, new byte[]{(byte) 0x13}); //Select the conversion mode (speed, filter..) which refers to 2x speed mode and selecting the 50Hz filter
Then we read the 32bits/4bytes of the conversion:
//After waiting 100ms for the conversion time, we read the output value through the I2C lineAfter so many tries, it still doesn’t get a response from the device nor it gets any error. Does anyone know how to solve this issue or have any
i2cModule.readData((byte)0x34, (byte)0x00, (byte)4).onComplete(new CompletionHandler<byte[]>() {
@Override
public void success(byte[] result) {
auxvar = result;
//Log.i("MainActivity", String.format("WHO_AM_I= %d", result[0]));
}
});
idea what would be the problem?
Thanks anyway.
This discussion has been closed.
Comments
I am using the C-CPRO board and the firmware it has is the 1.0.4. Is that the reason why it fails to communicate? Thanks for your previous answer
https://i.imgsafe.org/718f939.png
https://i.imgsafe.org/7273793.png
https://i.imgsafe.org/73406c3.png
https://i.imgsafe.org/7421815.png
https://i.imgsafe.org/41ce232.png
https://i.imgsafe.org/4280d8b.png
https://i.imgsafe.org/431cbde.png
https://i.imgsafe.org/7421815.png
The first and second link is the first stream I record and it is really weird that it doesn't send the second word of data. But what I don't understand is what happens from the 3rd picture in advance. It starts sending data to write and read from addresses I haven't put in my code. I don't know if you would have any clue what is going on.
If you need, I can send you through pm what the code looks like in more depth.
I have done what you said and retrieves without a problem 0x58. So what does this mean? How I can solve my initial problem?
Regards
Thanks for your response. I have done what you said but it was still the same. However I solved the issue by using the following code: Now it reads fine but I have right now two problems. The first problem is that when my program enter in the "timerModule.scheduleTask" execution loop, to do the writing, wait 150ms, reading and plotting and then repeat it after a period of time (is nearly the same as the one in the GPIO of the sample app); it can only do this execution only for 3-4 seconds (putting the timer at 250ms) it starts doing the fuzzy stuff that you said that was related to the bootup and suddenly my app tries to reconnect to the device and after that it cannot read anything from the I2C. After doing some arranges, it appears that if I leave out from the loop the writing to I2C code, it solves this problem but it is not a solution for me as I will need to write to the device to read other channels as well. Do you know why is happening this or how to solve this issue?
And the second problem is that when I try to read the data in the success function, I can only manipulate the data just inside that function and out of it I am not able to work with it. What I want t do is the following:
What I want to do with my application is to read the values from one channel, then read the value from the other channels, store them in auxiliar variables and repeat again 3 more times. This is done to later make an average of the samples obtained and plot the normalize value made by this and the maximum sample obtained. That is why I want to have the plot outside the success function. The code that is not working is the following:
Thanks for your explanation. I just have one doubt about this. As I will require to have the 4 samples obtained in each pass of the for loop, as the way you have described in your example, once we exit the success function (when have obtained both samples) and repeat again the loop, we won't be able to obtain the previous sample as we have exit the success function which had the data from the previous reading. So the data is lost. How to solve this issue?
And for the scheduleTask, just one small question. The only function I am using inside of this is the writing/reading of the i2c, the rest is the data manipulation and plotting. Is this the part that blocks the application?
Thanks for the help. I will let you know when I have implemented and tested the new code.
Regards.
I have tested the new application and at first seems ok, it reads and displays the value obtained from the i2c, there is a big problem which makes the bluetooth communication unstable and disconnects and reconnects every so and often it freezes the application or makes it slow. This is the code using Handler I have implemented: