DS2401 Silicon Serial Number help

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

DS2401 Silicon Serial Number help

Post by Ondra »

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
Attachments
OneWire_ChipID.fcf
(8.5 KiB) Downloaded 294 times

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: DS2401 Silicon Serial Number help

Post by Ondra »

Good day all. I could really uses some help on the guys.

Ondra

User avatar
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

Post by Benj »

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 ;)

Eric
Posts: 99
Joined: Tue Nov 06, 2007 11:04 pm
Been thanked: 1 time
Contact:

Re: DS2401 Silicon Serial Number help

Post by Eric »

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

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: DS2401 Silicon Serial Number help

Post by Ondra »

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

Eric
Posts: 99
Joined: Tue Nov 06, 2007 11:04 pm
Been thanked: 1 time
Contact:

Re: DS2401 Silicon Serial Number help

Post by Eric »

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

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: DS2401 Silicon Serial Number help

Post by Ondra »

Thanks Eric.
If I'm using Port C pin 3, do I use the same C code you recommended? : - adcon1 = 0x07;

Ondra

User avatar
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

Post by Benj »

Hi Ondra,

The code - adcon1 = 0x07; simply turns off the adc and allows the digital I/O to work correctly on analogue capable pins.

Eric
Posts: 99
Joined: Tue Nov 06, 2007 11:04 pm
Been thanked: 1 time
Contact:

Re: DS2401 Silicon Serial Number help

Post by Eric »

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

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: DS2401 Silicon Serial Number help

Post by Ondra »

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

User avatar
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

Post by Benj »

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.
Attachments
DS2401.fcf
(11.5 KiB) Downloaded 285 times

User avatar
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

Post by Benj »

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.

User avatar
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

Post by Benj »

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 212 times

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: DS2401 Silicon Serial Number help

Post by Ondra »

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

User avatar
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

Post by Benj »

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

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: DS2401 Silicon Serial Number help

Post by Ondra »

Thanks Ben. The system printed out a number 2.

Ondra

User avatar
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

Post by Benj »

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.
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Ω.
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.

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;
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.

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: DS2401 Silicon Serial Number help

Post by Ondra »

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

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: DS2401 Silicon Serial Number help

Post by Ondra »

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. "

User avatar
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

Post by Benj »

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.

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;
}
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)

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: DS2401 Silicon Serial Number help

Post by Ondra »

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

User avatar
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

Post by Benj »

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?

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: DS2401 Silicon Serial Number help

Post by Ondra »

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

User avatar
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

Post by Benj »

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.

Post Reply