View previous topic :: View next topic |
Author |
Message |
Prefekt
Joined: 21 Oct 2010 Posts: 85
|
|
![](templates/subSilver/images/spacer.gif) |
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Tue Dec 03, 2013 2:47 pm |
|
|
Hi,
Yes, in line 37 of your code replace the '=' with a '==', and that should solve the problem. Also, add 'Errors' to your #use rs232 declaration.
John
PS how are we supposed to offer any constructive suggestions if you don't post your code? |
|
![](templates/subSilver/images/spacer.gif) |
Prefekt
Joined: 21 Oct 2010 Posts: 85
|
|
Posted: Wed Dec 04, 2013 1:18 pm |
|
|
Ok, in the protocol datasheet are two different commands, DF 'Data Fetch' and MR 'Measuring Request'
The sensor address is 0x28:
first step: send MR with address and last bit = 0 as write
next: send DF with address and last bit =1 as read
next: read Data
next: read Data
next: read Data
next: read Data
I have no experience with i2c... here' a code snippet:
Code: |
i2c_start();
status = i2c_write(0b01010000);
if(status != 0)
{
printf("MR: no sensor found\n\r");
continue;
}
else
{
printf("MR: ok\n\r");
}
i2c_stop();
delay_ms(50);
i2c_start();
status = i2c_write(0b01010001);
if(status != 0)
{
printf("DF: no sensor found\n\r");
continue;
}
else
{
printf("DF: ok\n\r");
}
i[0] = i2c_read();
i[1] = i2c_read();
i[2] = i2c_read();
i[3] = i2c_read();
i2c_stop();
printf("%x # %x # %x # %x \n\r", i[0], i[1], i[2], i[3]);
delay_ms(500);
|
the output is:
MR: ok
DF: ok
ff # ff # ff # ff
MR: ok
DF: ok
ff # ff # ff # ff
MR: ok
DF: ok
ff # ff # ff # ff
MR: ok
DF: ok
ff # ff # ff # ff |
|
![](templates/subSilver/images/spacer.gif) |
Prefekt
Joined: 21 Oct 2010 Posts: 85
|
|
Posted: Tue Dec 17, 2013 11:49 pm |
|
|
Now, the sensor is working - sometimes.
The read values are wrong. At the first read / write the sensors answers, but the than ' status = i2c_write(AddressWrite);' failed.
Code: |
void GetSensorData(char AddressWrite, char AddressRead)
{
int status=0;
int i=4;
i2c_start();
status = i2c_write(AddressWrite);
if(status != 0)
{
printf("MR: no sensor found at:%x \n\r", AddressWrite);
continue;
}
else
{
printf("MR: ok\n\r");
}
i2c_stop();
delay_ms(100);
i2c_start();
status = i2c_write(AddressRead);
if(status != 0)
{
printf("DF: no sensor found at: %x \n\r", AddressRead);
continue;
}
else
{
printf("DF: ok\n\r");
}
for (i=0;i<4;i++)
{
messageBuf[i] = i2c_read();
}
i2c_stop();
printf("%x # %x # %x # %x \n\r", messageBuf[0], messageBuf[1], messageBuf[2], messageBuf[3]);
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
|