A working 1-wire driver and sample!

Post details of your projects here.
Post Reply
logictechs
Posts: 6
Joined: Sat Dec 27, 2014 2:35 am

A working 1-wire driver and sample!

Post by logictechs » Sun Jan 04, 2015 8:46 am

Hi All,

I received my PROstart and LPC812 boards last Friday! Being a 1-wire guru, I wanted to test the 2 boards interfacing with some 1-wire devices. I was disappointed to find the existing 1-wire BASIC driver not functional. So I whipped out my LOGIC analyzer and started tinkering with the existing driver. The attached driver and example file is a preliminary work tested with the PROstart board and my unowire board. I hope to expand it to add the rom search function as I use multi-drop networks most of the time. With the attached driver you can at least get 1 rom and read/write bytes. Please let me know if there already is an existing driver to do more functions! I looked around on here quite a bit before I began my tinkers to make it work.

Regards,

David Kaleta
Attachments
1_WireDriverExample.zip
1-wire driver and example. PROstart tested.
(1.36 KiB) Downloaded 176 times



logictechs
Posts: 6
Joined: Sat Dec 27, 2014 2:35 am

Re: A working 1-wire driver and sample!

Post by logictechs » Mon Jan 05, 2015 6:56 am

Hi again,

Just wanted to update with info about usage of this driver with the LPC812. It works also! I tested with my unowire board having a DS2408 (8 channel I/O) to get its ROM id using IO17 of the LPC812. Lots of ideas flowing through my head with using this gadget now!
LPC812unowireworking.jpg
LPC812unowireworking.jpg (124.51 KiB) Viewed 4798 times

basicchip
Posts: 839
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: A working 1-wire driver and sample!

Post by basicchip » Thu Jan 08, 2015 1:14 am

Hi David-

Thanks for the fixes, not sure I even have any of the one wire temp sensors I use to have to test this (last checked in 2008).

I turned off interrupts around the code to make sure they were not an issue. Potentially you could have a UART interrupt occur, even though they are pretty short, in theory it could affect timing.

When you turn off interrupts these days that affects code of the form

Code: Select all

start = TIMER
while ((TIMER - start) < x)
loop
Now that Cortex parts are using Systick, they need at least the Systick interrupt to be running for those to work.

So in most places I have started using WAIT_MICRO which will work even when Systick interrupts are turned off. WAIT_MICRO is also more accurate as it has less overhead than TIMER. It does have the limitation of being usable up to a max of 65000 microseconds.

To safely turn off interrupts when you use TIMER use this code

Code: Select all

INTERRUPT(0)
ST_CTRL OR= 2   ' re-enable Systick interrupts -- check the name this is the SuperPRO version
And David if you don't mind could you check my additional edits to ONEWIRE.bas ?

If it works I'll update the library file in the installer
ONEWIRE.bas
(2.18 KiB) Downloaded 169 times

logictechs
Posts: 6
Joined: Sat Dec 27, 2014 2:35 am

Re: A working 1-wire driver and sample!

Post by logictechs » Thu Jan 08, 2015 3:35 pm

Hi Bruce,

Thanks for all the info and revision. If you noticed, I had left the TIMER based stuff in the reset function as it didn't create any issues during my simple tests. Using my LOGIC analyser, everything seemed ok. In my tester program, I wasn't working it right I guess to "create" an issue. Using the turn of interrupts didn't seem to have any effects either so I left it out to save some code space. I was actually thinking at one point to use an interrupt to catch the acknowledge of reset pulse from the 1-wire device. I suppose I could have used the PULSIN command that I found now. I think what we have now should work. I'll test your version later on today and let you know how it works.

Regards,

David Kaleta

basicchip
Posts: 839
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: A working 1-wire driver and sample!

Post by basicchip » Thu Jan 08, 2015 3:51 pm

Interrupts turned off and TIMER with Systick will fail VERY infrequently, but eventually it would fail.

PULSIN is in the obsolete bin these days, as it was left over from the days when we were trying to build something compatible with the BASIC stamp. That market seems to be completely dead these days having been replaced by Arduino in the DIY community. We leave it around just for those few people that move over from PBASIC and as sample code.

INTERRUPT(0) turns off all interrupts, you can always turn individual ones on by writing to the NVIC registers.

For accurate pulse timing measures you should use the timer capture hardware.

logictechs
Posts: 6
Joined: Sat Dec 27, 2014 2:35 am

Re: A working 1-wire driver and sample!

Post by logictechs » Fri Jan 09, 2015 6:07 am

Hi Bruce,

I tested your revised driver and it seems to work fine. I think it's good to go into the next install package. Multidrop on 1 I/O line functionality can come at a later time. I was able to use another line for a second sensor channel to get by for now. Just depends what the end user needs.

Regards,

David Kaleta

Post Reply