Hey guys, i am posting my problem here again, in hopes that my mind will flicker and i understand everything again, or if that won't work then maybe one of you could show me the light.
As my title shows, i am trying to read from 1wire ds2401 device. I should basically just get a lot of bits that will show a serial number.
Here are the functions that should take care of all the madness inside.
i "borrowed" the OWReadByte function, because i didn't get my own function to work, but neither does this(at least i know it worked for someone).
DW-Data Write
and
DR - Data Read
I keep getting the same result, when i am reading. I am trying to put the result from ReadByte onto LEDs to see the output, but thus far i keep getting the same thing.
The device is connected directly to Port 3.4 and 3.5 and nothing should be able to screw it up.
The "reset" of the 1 wire is good and that is why i am not posting it here. I checked it with oscilloscope and i get a nice presence.
Also, the input and output signals should be inverted because of the circuits, that is why inversion can be seen in the code.
To recap
I am calling the function OWWriteByte(0x0F); to run the "read ROM" and then i am trying to get the result without any luck. On the LEDs i keep getting 0b01111111
EDIT!
So now i can get something on the LCD, something.
I get some weird characters.
EDIT!
So i did some decoding, from binary to hex, and i think i am actually getting the right values, just in wrong order.
EDIT!
So i decided to try and use sprintf in this way
I get the family code and CRC and the Serial in between. I have a example hex program where the hex values from the serial are flipped tho, which is odd. I don't know if i am wrong or the example maker is wrong. The family and CRC match tho.
A problem i countered is that all the hex values have ff in front of them, and i can not understand where that comes from.
For example, ff01 when it should be just 01
EDIT
I can now print the whole thing out
I masked the FFs out.
I still have a problem with the fact that the serial code it self comes out backwards.
As my title shows, i am trying to read from 1wire ds2401 device. I should basically just get a lot of bits that will show a serial number.
Here are the functions that should take care of all the madness inside.
Code:
int OWReadBit(void)
{
int result;
DW=1; // Drives DQ low
DW=0; // Releases the bus
t0delay(0);
result = DR; // Sample the bit value from the slave
t0delay(3); //
return ~result;
}
int OWReadByte(void)
{
int loop, result=0;
for (loop = 0; loop < 8; loop++)
{
// shift the result to get it ready for the next bit
result >>= 1;
// if result is one, then set MS bit
if (OWReadBit())
{
result=result | 0x80;
}
}
return result;
}
void OWWriteBit(int bit)
{
*led=bit;
if (bit==1) //write 1
{
// Write '1' bit
DW=1; // Drives DQ low
//tickDelay(A);
DW=0; // Releases the bus
t0delay(4);
}
else if(bit==0) //write 0
{
// Write '0' bit
DW=1; // Drives DQ low
t0delay(3);
DW=0; // Releases the bus
t0delay(0);
}
}
void OWWriteByte(int data)
{
int loop;
// Loop to write each bit in the byte, LS-bit first
for (loop = 0; loop < 8; loop++)
{
OWWriteBit(data & 0x01);
// shift the data byte for the next bit
data = data>>1;
}
}
DW-Data Write
and
DR - Data Read
I keep getting the same result, when i am reading. I am trying to put the result from ReadByte onto LEDs to see the output, but thus far i keep getting the same thing.
The device is connected directly to Port 3.4 and 3.5 and nothing should be able to screw it up.
The "reset" of the 1 wire is good and that is why i am not posting it here. I checked it with oscilloscope and i get a nice presence.
Also, the input and output signals should be inverted because of the circuits, that is why inversion can be seen in the code.
To recap
I am calling the function OWWriteByte(0x0F); to run the "read ROM" and then i am trying to get the result without any luck. On the LEDs i keep getting 0b01111111
EDIT!
So now i can get something on the LCD, something.
I get some weird characters.
EDIT!
So i did some decoding, from binary to hex, and i think i am actually getting the right values, just in wrong order.
EDIT!
So i decided to try and use sprintf in this way
Code:
while(1)
{
if(getkey()=='g')
{
sprintf(str_2, "%X", ~OWReadByte());
lcd_delay();
lcd_string(str_2);
lcd_delay();
A problem i countered is that all the hex values have ff in front of them, and i can not understand where that comes from.
For example, ff01 when it should be just 01
EDIT
I can now print the whole thing out
I masked the FFs out.
Code:
sprintf(str_2, "%02X", (~OWReadByte()&0xFF));
Last edited: