#include <Wire.h>
#define DSCP01_ADDRESS 0x10
void setup() {
Serial.begin(9600);
Wire.begin();
}
void loop() {
Wire.beginTransmission(DSCP01_ADDRESS);
Wire.write(0x70); // wake up
int test = Wire.endTransmission();
if (test != 0) {
Serial.println("Transmission failed:");
Serial.println(test);
}
// wait for the sensor to wake up
delay(1000);
// send temperature command
Wire.beginTransmission(DSCP01_ADDRESS);
Wire.write(0x80); // request temperature
Wire.endTransmission();
Wire.requestFrom(DSCP01_ADDRESS, 2);
if (Wire.available()) {
uint t = Wire.read();
t <<= 8;
t |= Wire.read();
int temperature = (t & 0x8000) ? -(t &0x7FFF) : t & 0x7FFF;
Serial.print("Temp: ");
Serial.print((float)temperature/10.0);
Serial.println(" C");
}
// go to sleep
Wire.beginTransmission(DSCP01_ADDRESS);
Wire.write(0x71); // sleep
Wire.endTransmission();
delay(5000); // wait a bit, temperatue isn't changing fast
}
first of all - thx for your answer - i hoped this thread isnt dead
serial output:
Transmission failed:
2
Transmission failed:
2
so i dont get an acknowledge....but that could have several reasons - or do u have any suggestions ?
( i've to say that i dont have an oszillograph/oszi at home ... so error detection might be hard or impossible ? )
note:in your nice test prog:
at thise line is an "u" where it doesnt belong to ^^
Based on some code written for a PIC controller to be used with this module, I changed the test code to the following. Could you try it?
#include <Wire.h>
#define DSCP01_ADDRESS 0x10
void setup() {
Serial.begin(9600);
Wire.begin();
int res = 2;
while (res != 0) {
Wire.beginTransmission(DSCP01_ADDRESS);
Wire.write(0x70); // wake up
res = Wire.endTransmission();
}
// wait for the sensor to wake up
delay(1000);
}
void loop() {
// send temperature command
Wire.beginTransmission(DSCP01_ADDRESS);
Wire.write(0x80); // request temperature
int test = Wire.endTransmission();
if (test != 0) {
Serial.println("Transmission failed:");
Serial.println(test);
}
delay(200); // seems to be necessary
Wire.requestFrom(DSCP01_ADDRESS, 2);
if (Wire.available()) {
uint16_t t = Wire.read();
t <<= 8;
t |= Wire.read();
int temperature = (t & 0x8000) ? -(t &0x7FFF) : t & 0x7FFF;
Serial.print("Temp: ");
Serial.print((float)temperature/10.0);
Serial.println(" C");
}
delay(1000); // wait a bit, temperatue isn't changing fast
}
hm - now i dont get any response on the serial monitor
not even that connection failed or like last time no acknowledge
hm could i somehow destroyed something during the soldering process ?
im used to soldier a bit (built a few led cubes, my own litle radio device, power adapter and so on ... )
and i thought i soldered those 4 little pins quite well ... but now im not quite sure if i did something wrong - or im just a to big beginner that i get any response
the only things i built so far with an arduino was an led cube and a motor driver
The last change I did was ignoring the NAKs the Arduino gets from the module until it wakes up. I did that because the example code for the PIC did the same (although this was not specified in the datasheet). Maybe it runs now in an endless loop if the module does not wake up and answers with an ACK.
If you have one try to attach a scope or logic analyzer and check if the module is answering to any request. Debugging with just software changes gets now quite complicated. I'm not sure if your module got burned, it may be some other problem, but without checking the signal it's very difficult to help you more.
One thing you could try is programming your Arduino to continually request the temperature from the module and starting (powering) the Arduino a few seconds before you put power to the Vcc of the module. This way it should never go to sleep and immediately answer the requests.
No, you cannot use the sketch I posted, you need to modify it for this last check.
You have to remove all delay()s in loop(), the rest probably should work.
If that doesn't work, it's not the stand-by handling that is causing troubles. Without a scope I would guess that the module is damaged.
but looks bad - commented out the "delays" in the loop, loaded the sketch with Vcc not connected to the sensor - restarted arduino and plugged in Vcc-Sensor - but no response on the SerialMontior
hm i just wonder i added in this loop
while (res != 0)
{
Wire.beginTransmission(DSCP01_ADDRESS);
Wire.write(0x70); // wake up
res = Wire.endTransmission();
println(res);
Serial.println(res);
}
the last line so that it should print me again the NAK - but i only get one response - do i have a missunderstanding what the written line should do ?
hm would there be a solution with a simple loop which and trial which runs through all possible adresses and if there is a result - an aknowledge - i print it
and maybe an second while or whatever which runs through different delay times in principle like that:
int time_var // start from 10ms ...1s
int adr_var // start from logic "good" adress to an end adress
for(;;time++) while no correct answer <- time varialbe loop
{
for(;; adr ++) while no correct answer <- adr. varialbe loop
{
send and wait if response like in your loop !=2 (an other value than NAK/2)
if(correct response) - JEAH ...do sth
}
}
or doesnt that have any use - because that i didnt get an asnwer in the 2 test programms you wrote
me includes those cases ?
You may try that one, but I doubt that it will have another address, the datasheet clearly specifies 0x20 and 0x21 which translates to a 0x10 in 7-bit format.
Have you tried running it without the device connected? It should run through without a problem. If it doesn't your Arduino board has a problem.
Usually this code runs through and displays the found devices (if you don't comment out the necessary lines). There is almost no way of letting it break (almost because a slave device can make the communication slower by holding the SCKL low for longer than the master intended. But that means the slave gets active and it has to implement that feature (most don't).
yes i tried it without the sensor connected and it works as it should
hm not sure if i did get your second point, where you explained how that could be
so - if i understand right it means the device works and holds down the CLK line and my arduino waits for
an high impulse on the CLK ?
ok i now look at my old IC´s if there is an other I2C device and test this and try if i get it running, when my sensor dont want to work
so - if i understand right it means the device works and holds down the CLK line and my arduino waits for
an high impulse on the CLK ?
Almost. Usually I2C devices are just slaves, the master is controlling everything. The master is pulsing the clock line (spikes from high to low) which is giving the frequency for the serial transfer (in either direction). If a slave needs more time to fulfill it's task, it is allowed to hold the clock low even if the master isn't still pulling it (clock stretching). I don't know where the limits are for this feature but in every description I read it sounds like: "it's allowed to stretch the clock a little bit".
The blocking of the bus like you may experience is clearly a misbehavior.