DS2401 Silicon Serial Number help
Moderator: Benj
DS2401 Silicon Serial Number help
Good day all. I have been trying to get the DS2401 one wire product working over the weekend. I have tried everything possible, with no success.
The first question is does V4 have the support to work with the DS2401. If so can someone please give some assistance on programming the device. I have attached my code to see if someone can spot what I might be missing. What I'm attempting to do is capture each byte value sent from the device and bit bang it out to my PC. I put the scope on the chip to see if I can see what's going on but nothing seems to be working at all. The pin going low. The data byte being transmitted. The only thing that's working is a LED flashing which I included to verify that the code is running.
Ondra
http://datasheets.maxim-ic.com/en/ds/DS2401.pdf
The first question is does V4 have the support to work with the DS2401. If so can someone please give some assistance on programming the device. I have attached my code to see if someone can spot what I might be missing. What I'm attempting to do is capture each byte value sent from the device and bit bang it out to my PC. I put the scope on the chip to see if I can see what's going on but nothing seems to be working at all. The pin going low. The data byte being transmitted. The only thing that's working is a LED flashing which I included to verify that the code is running.
Ondra
http://datasheets.maxim-ic.com/en/ds/DS2401.pdf
- Attachments
-
- OneWire_ChipID.fcf
- (8.5 KiB) Downloaded 295 times
Re: DS2401 Silicon Serial Number help
Good day all. I could really uses some help on the guys.
Ondra
Ondra
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: DS2401 Silicon Serial Number help
Hello Ondra,
Sorry for the delay. I will have a look into this when I next get some free time. Im afraid its been a bit hectic recently. I have no experience with using this device perhaps one of our forum users has already come across this and can shed some light onto the subject. Keep this topic active and if no one can help then it might be worth going to the freelance engineers and seeing if any of them fancy the challange. I will try and find some time this week to look at this for you though it depends how well the testing of the internal can driver goes tonight
Sorry for the delay. I will have a look into this when I next get some free time. Im afraid its been a bit hectic recently. I have no experience with using this device perhaps one of our forum users has already come across this and can shed some light onto the subject. Keep this topic active and if no one can help then it might be worth going to the freelance engineers and seeing if any of them fancy the challange. I will try and find some time this week to look at this for you though it depends how well the testing of the internal can driver goes tonight
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: DS2401 Silicon Serial Number help
Hello Ondra,
I think you need to do 2 things:
1) add the following c-code at the beginning of your program: adcon1 = 0x07;
2) connect the one wire device to port A0 and change the connection properties to A0 in the property field of the one-wire component
Best regards,
Eric
I think you need to do 2 things:
1) add the following c-code at the beginning of your program: adcon1 = 0x07;
2) connect the one wire device to port A0 and change the connection properties to A0 in the property field of the one-wire component
Best regards,
Eric
Re: DS2401 Silicon Serial Number help
Thanks Eric.
I'm adding this device to en existing system. The only available pin is C3. Are you saying that the one wire device cannot work on port pin C3?
Ondra
I'm adding this device to en existing system. The only available pin is C3. Are you saying that the one wire device cannot work on port pin C3?
Ondra
Re: DS2401 Silicon Serial Number help
Hello Ondra,
It is possible to use C3.
I suggested PORTA0 only to eliminate possible differences between my hardware ( where I tested it ) and your hardware.
Best regards,
Eric
It is possible to use C3.
I suggested PORTA0 only to eliminate possible differences between my hardware ( where I tested it ) and your hardware.
Best regards,
Eric
Re: DS2401 Silicon Serial Number help
Thanks Eric.
If I'm using Port C pin 3, do I use the same C code you recommended? : - adcon1 = 0x07;
Ondra
If I'm using Port C pin 3, do I use the same C code you recommended? : - adcon1 = 0x07;
Ondra
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: DS2401 Silicon Serial Number help
Hi Ondra,
The code - adcon1 = 0x07; simply turns off the adc and allows the digital I/O to work correctly on analogue capable pins.
The code - adcon1 = 0x07; simply turns off the adc and allows the digital I/O to work correctly on analogue capable pins.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: DS2401 Silicon Serial Number help
Hi Ondra,
I migrated once from a PIC18F452 to a PIC18F8250 ( due to lack of output ports).
There I noticed that everything worked as before except for the onewire sensors.
When I examined the C code, I noticed that for the PIC18F452 Flowcode compiled as first command: adcon1 = 0x07;
For the PIC18F8250 it compiled: adcon1 = 0x0F;
When I changed the 0x0F into 0x07, onewire was working again.
Because for your PIC, Flowcode also compiles adcon1=0x0F, hence my suggestion to overwrite it with a separate c-code.
Best regards,
Eric
I migrated once from a PIC18F452 to a PIC18F8250 ( due to lack of output ports).
There I noticed that everything worked as before except for the onewire sensors.
When I examined the C code, I noticed that for the PIC18F452 Flowcode compiled as first command: adcon1 = 0x07;
For the PIC18F8250 it compiled: adcon1 = 0x0F;
When I changed the 0x0F into 0x07, onewire was working again.
Because for your PIC, Flowcode also compiles adcon1=0x0F, hence my suggestion to overwrite it with a separate c-code.
Best regards,
Eric
Re: DS2401 Silicon Serial Number help
Thanks Eric and Ben. On the PIC 18F2680 which I'm using, RC3 is not an Analogue capable pin.
Any other Idea on this one?
Ondra
Any other Idea on this one?
Ondra
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: DS2401 Silicon Serial Number help
Hello Ondra,
I have finally managed to get around to looking into this for you.
I have created a test program that is working well with the DS2401 devices Also works with CRC checking on and off so its up to you if you want to use it.
I have used the ECIO for my demo program so hopefully you can change the connections and clock speeds etc to match your circuit design and it will also work for you.
Also just to confirm Are you using a pull up resistor of around 5K on the data line? Because it wont work without one. Took me a while to notice that.
I have finally managed to get around to looking into this for you.
I have created a test program that is working well with the DS2401 devices Also works with CRC checking on and off so its up to you if you want to use it.
I have used the ECIO for my demo program so hopefully you can change the connections and clock speeds etc to match your circuit design and it will also work for you.
Also just to confirm Are you using a pull up resistor of around 5K on the data line? Because it wont work without one. Took me a while to notice that.
- Attachments
-
- DS2401.fcf
- (11.5 KiB) Downloaded 288 times
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: DS2401 Silicon Serial Number help
If the code above does not work then you can try adding the following code to ensure that both the SPI and I2C interfaces that have access to pin RC3 are disabled.
cr_bit (sspcon1, SSPEN);
These peripherals are switched off by default at startup on these devices but as a last resort it may be worth testing.
cr_bit (sspcon1, SSPEN);
These peripherals are switched off by default at startup on these devices but as a last resort it may be worth testing.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: DS2401 Silicon Serial Number help
Here is a less error checking application once you have the device working. It collects the ID data and then transmits via a bit banged RS232 connection. You can change the properties and connections of the RS232 component as you wish to suit your application.
- Attachments
-
- DS2401_a.fcf
- (7 KiB) Downloaded 214 times
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: DS2401 Silicon Serial Number help
Hi Ben.
First, thanks for everything and especially for going the extra mile.
I loaded the code with the changes to suit my hardware. The reset devices returns an OK. Scan devices returns a Fail, and of course
device ID returns 255. I tried using a c code block with the code ("cr_bit (sspcon1, SSPEN);") you suggested and I got the same results.
The device is about 15cm from the MCU I have a 4.7k pull-up resistor on pin 2, the data pin, and pin 1 is connected to ground. I' using an 18F2680 chip with a 19660800 crystal. I tried with and with out CRC. Is there anything else you can think of that I might be missing?
Ondra
First, thanks for everything and especially for going the extra mile.
I loaded the code with the changes to suit my hardware. The reset devices returns an OK. Scan devices returns a Fail, and of course
device ID returns 255. I tried using a c code block with the code ("cr_bit (sspcon1, SSPEN);") you suggested and I got the same results.
The device is about 15cm from the MCU I have a 4.7k pull-up resistor on pin 2, the data pin, and pin 1 is connected to ground. I' using an 18F2680 chip with a 19660800 crystal. I tried with and with out CRC. Is there anything else you can think of that I might be missing?
Ondra
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: DS2401 Silicon Serial Number help
Hello Ondra,
If the scan for devices macro is failing then you can use a printnumber LCD component macro to print out the retval variable. This should show you an error code that may help to pinpoint the problem.
In my test prog simply add the print number under the "failed" statement.
1 -> Reset error
2 -> Bus Logic Fault
Anything else - Indicates a CRC error
If the scan for devices macro is failing then you can use a printnumber LCD component macro to print out the retval variable. This should show you an error code that may help to pinpoint the problem.
In my test prog simply add the print number under the "failed" statement.
1 -> Reset error
2 -> Bus Logic Fault
Anything else - Indicates a CRC error
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: DS2401 Silicon Serial Number help
Hi Ondra,
Right the error number 2 is returned when the one wire receives two consecutive logic 1's from the bus during a scan for nodes. This indicates that no node responded to the request.
I then found this on wikipedia.
It may also be worth playing with the rx_bit function using the code customization feature of v4. changing to match the following may help.
As you can see the code above waits a bit longer before sampling the incoming bit. This may be enough to overcome the problems you are having.
Right the error number 2 is returned when the one wire receives two consecutive logic 1's from the bus during a scan for nodes. This indicates that no node responded to the request.
I then found this on wikipedia.
Maybe its worth playing with the pullup resistance to see if this can make it work correctly. I used a pullup of 8K on my hardware here.Up to 300 meter long buses consisting of simple twistedpair telephone cable has been tested by the manufacturer. It will however require adjustment of pull-up resistances from say 5kΩ to 1 kΩ.
It may also be worth playing with the rx_bit function using the code customization feature of v4. changing to match the following may help.
Code: Select all
char oo_bit, count;
Clear_OO; //Clear Output Pin
delay_us(1); //Delay 1us
Float_OO; //Float Output Pin
delay_us(20); //********************************Delay 20us was 10us
oo_bit = ts_bit(OO_PORT, OO_PIN); //Test Input
delay_us(40); //********************************Delay 40us was 50us
return oo_bit;
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: DS2401 Silicon Serial Number help
Good day Ben, and thanks again.
I got up this morning and tried everything you suggested with the code changes. I connect a variable resistor and tried different values and I still get the failed error code 2.
Anything else I can try?
Ondra
I got up this morning and tried everything you suggested with the code changes. I connect a variable resistor and tried different values and I still get the failed error code 2.
Anything else I can try?
Ondra
Re: DS2401 Silicon Serial Number help
Ben, going through the data sheet and the flowchart for the DS2401 I read the instructions below. I don't see where this is happening in your code.
Could you advise.
Ondra
"Read ROM [33h] or [0Fh]
This command allows the bus master to read the DS2401’s 8-bit family code, unique 48-bit serial
number, and 8-bit CRC. This command can only be used if there is a single DS2401 on the bus. If more
than one slave is present on the bus, a data collision will occur when all slaves try to transmit at the same
time (open drain will produce a wired-AND result). The DS2401 Read ROM function will occur with a
command byte of either 33h or 0Fh in order to ensure compatibility with the DS2400, which will only
respond to a 0Fh command word with its 64-bit ROM data. "
Could you advise.
Ondra
"Read ROM [33h] or [0Fh]
This command allows the bus master to read the DS2401’s 8-bit family code, unique 48-bit serial
number, and 8-bit CRC. This command can only be used if there is a single DS2401 on the bus. If more
than one slave is present on the bus, a data collision will occur when all slaves try to transmit at the same
time (open drain will produce a wired-AND result). The DS2401 Read ROM function will occur with a
command byte of either 33h or 0Fh in order to ensure compatibility with the DS2400, which will only
respond to a 0Fh command word with its 64-bit ROM data. "
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: DS2401 Silicon Serial Number help
Hello Ondra,
Thats a shame thought I might be onto something then.
The return code of 2 is coming from the oo_get_next_id() function.
Specifically this portion.
May be worth trying using E-Blocks or some alternate hardware just to make sure your device is not damaged and that your hardware is correct. As I say the device is working well for me so I dont think it is the code at fault. I have had experience of damaging one wire devices before simply by looking at them. (maybe I wired the wrong polarity as well as looking at it but they are very easy to damage it seems)
Thats a shame thought I might be onto something then.
The return code of 2 is coming from the oo_get_next_id() function.
Specifically this portion.
Code: Select all
// Read 2 consecutive bits from the One Wire bus
val0 = rx_bit(); //Test Input
val1 = rx_bit(); //Test Input
// Evaluate the result
if ((val0 == 0) && (val1 == 0))
{
//current_conflict = counter;
// if conflict occurs earlier than the previous conflict, then use the previous value
if (counter < conflict)
{
// use previous value
bit_test = id[byte_index] >> bit_index; //added JCMB 10/01/09
if (bit_test & 0x01)
{
val0 = 1;
}
else
{
val0 = 0;
lz_selected = counter; //added JCMB 10/01/09
go_on = 1; //added JCMB 10/01/09
}
}
else if (counter == conflict)
{
// use 1
val0 = 1;
}
else
{
// use zero on new conflicts
val0 = 0;
conflict = counter;
new_conflict = 1;
}
}
else if (val0 && val1) // 1 et 1 impossible
{
return 2;
}
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: DS2401 Silicon Serial Number help
Hi Ben. Thanks for your response I purchased 5 ID chips. I sent another unit in a different circuit and I got the same results.
I discovered one thing though. When I take the device out of the circuit, I still get an OK on the bus_reset. Is that a bug? according to the help file I should have gotten a 1. I used a scope to look at the signal. I can see that the one_Wire device is responding with a 0 after about 600us. I'm unable to tell what's going on after that. Is it possible that the MCU that I am using has limitations for performing this function on that pin? If can't get this working, could you advise on a way to get a unique ID for a device. Is there away when programming to say write a unique value to the eprom of a Chip. One that can be incremented on each upload to a device. Or do you know of another device that can give me a unique Id?
Ondra
I discovered one thing though. When I take the device out of the circuit, I still get an OK on the bus_reset. Is that a bug? according to the help file I should have gotten a 1. I used a scope to look at the signal. I can see that the one_Wire device is responding with a 0 after about 600us. I'm unable to tell what's going on after that. Is it possible that the MCU that I am using has limitations for performing this function on that pin? If can't get this working, could you advise on a way to get a unique ID for a device. Is there away when programming to say write a unique value to the eprom of a Chip. One that can be incremented on each upload to a device. Or do you know of another device that can give me a unique Id?
Ondra
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: DS2401 Silicon Serial Number help
Hello Ondra,
Ah its strange that the reset is still working with the sensor disconnected. I tested this at home and I was getting the reset failed responce when the sensor was not connected. Is the pin definatley pulled up to 5V when the sensor is not present?
Ah its strange that the reset is still working with the sensor disconnected. I tested this at home and I was getting the reset failed responce when the sensor was not connected. Is the pin definatley pulled up to 5V when the sensor is not present?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: DS2401 Silicon Serial Number help
The first thing I did was check the pull-up, and yes I'm getting 4.89V at the data pin. May be I got a bunch of bad chips. May be the customs officers ran the devices through a scanner and damaged them. I started this about a month now, I'm going to let this go. Thanks for all your help Ben. Is it possible to write values to the eeprom during programming then read those values into a variable when the program is running?
Ondra
Ondra
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: DS2401 Silicon Serial Number help
Hello Ondra,
Please let me know if you make any progress,
The reset command simply asserts the bus low and then waits 60us before testing the bus. If the bus is at 5V then an error is returned. If the bus is at 0V then the 1 wire device is acknowledging the reset and the reset command completes correctly.
Please let me know if you make any progress,
The reset command simply asserts the bus low and then waits 60us before testing the bus. If the bus is at 5V then an error is returned. If the bus is at 0V then the 1 wire device is acknowledging the reset and the reset command completes correctly.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel