Bit Bang Challenge - cont

Michael 2727

Senior Member
Code WANTED here.
If you have successfully managed to communicate
with ANY device and wish to share the code
whether self written, begged, borrowed or stolen
Please share it with us.

Just list the device first then the code,
followed by any relevant comments at the end.

I am trying to read a Dallas DS1620 8 pin
Temperature Sensor similar to the DS18B20
but with 3 setpoint outputs, not having a
lot of joy, if you wish to help, e-mail me
or just post it here, that would be a nice start,,,~;o).

It seems this question is asked often enough about various devices.

It thought would be nice to see what can
or cannot be achieved, before you spend hours banging your head against the wall trying something that may or may not be
possible in the end.

I have read the Shiftin/out routines
from pages 82 to 85 of picaxe_manual2.pdf.

PICAXE related only please, not ARV etc, start a new post if need be.

There made it nice and fluffy and policically correct this time, I hope.

Edited by - Michael 2727 on 1/16/2006 3:56:52 PM
 

hippy

Technical Support
Staff member
PICAXE to DS1620 code can be found here ...

http://www.micromegacorp.com/downloads/documentation/uMFPU-V2%20PICAXE.pdf

pp14-16

Edited by - hippy on 1/16/2006 11:40:54 AM
 

Technical

Technical Support
Staff member
The aggresive 'tone' of this post is not appreciated on this forum, please read the protocol guidelines above.

The program link provided by 'Frank' in the earlier post on the archived forum will work perfectly with an 08/08M. If used with a 18 or 28 you will need to connect the data i-o pin to both a PICAXE output and input to be able to bidirectionally share data. Make sure you use a 1k resistor between the PICAXE output and temp ensor pin to avoid output clashes. Then use the program as is, but removing any input or output commands.
 

manuka

Senior Member
Aside from such obvious resources as =&gt; http://electronics.howstuffworks.com/microcontroller6.htm <A href='http://electronics.howstuffworks.com/microcontroller6.htm ' Target=_Blank>External Web Link</a> perhaps check Peter Anderson's insights =&gt;www.phanderson.com/picaxe/picaxe.html <A href='http://www.phanderson.com/picaxe/picaxe.html' Target=_Blank>External Web Link</a>as he's done a <b>lot </b> with such Dallas ICs &amp; (PBASIC) Basic Stamps.

But what are you trying to do? I'd a bit of fun myself with the DS1620 many years back (~Y2K?), BUT would have to query the appeal of it now. Quite aside from it's 8 pins, Picaxe interfacing to smaller(&amp; hence less thermal mass/more responsive),simpler,cheaper &amp; possibly superior 3 pin DS18B20 is a 08M READTEMP breeze. Surely any temperature set points ( or C-F conversions etc) can be now super easily rustled up in software ? You can't beat the DS18B20 for low parts count /tight code =&gt; www.picaxe.orcon.net.nz/433rpt.jpg <A href='http://www.picaxe.orcon.net.nz/433rpt.jpg ' Target=_Blank>External Web Link</a>



Edited by - Stan. swan on 1/16/2006 6:23:05 PM
 

andrewpro

New Member
The reason (at least as far as I'm concerned) that you dont see alot of specific bit banging answers is two fold:

1) If you have been through the numerous picaxe sites that are constantly posted here, like hippy's, stans, peter andersons (and others, I'm not purposely leaving anyone out!) youll find jsut about everyhitng you need to know. If it's not on any of those sites, it's in here. It really is! Why regurgitate the same things over and over again, when you can jsut point someone in the direction they need to go? Which leads us to:

2) Anyhitng that isn't on the forum and not often answered specifically is because this is a place of learning. The best way to learn is to figure it out, sometimes with a healthy bit of pointing from the good people here. If you were given the answers every time, youd learn only how to duplicate someone elses work.

If it doesn't work, instead of asking for someone else to do it, ask why it doesn't work? And be specific as possible. Tell what youve done, what the expected outcome was, what the actual outcome was, and from there you can get help in troubleshooting why the expected outcome was not the actual outcome. You have to be specific and detailed though, the more the better.

As for the DS1620, I had a gander at the data sheet, and the code for it is pretty straight forward and spelled out in the data sheet (so to speak). Take the reset line high, and start clocking data into bits on the picaxe. Check the section of the datasheet under &quot;3-wire communications&quot; starting on page 6.
 

hippy

Technical Support
Staff member
Bit-banging is in principle quite straight forward, being nothing more than setting and lowering lines in the right sequence. It gets a bit complex with bi-directional I/O lines, but that 1K trick with a separate input and output seems to work on PICAXE's which don't do bi-directional I/O. It's usually necessary to pull the output low to be able to read the input.

The real problems come when a 'command' is banged out and nothing happens or unexpected data is returend. Unless there are very specific timing requirements for the device it's usually down to wiring error, not sending the right signals in the right order, or not having fully understood the data sheet, and sometimes the datasheet being is just wrong or unclear ( polarity of signals, which edge data is clocked in and out on ). Fully understanding the datasheet and being friends with Google can go a long way. Dry running the program on paper and drawing what the I/O lines are doing ( like a scope trace ) can show where problems may lie.

If bit-banging doesn't work, and it rarely does first time because of some programming error, the most reliable way I've found to get it to work is by writing a PICAXE program which reads serial from a PC and allows manual control of raising and lowering lines, with the line status and what the device is giving back being returned. That usually shows up how the device works compared to how one thought it should. Devices which lend themselves to bit-banging will usually keep their data static until a line is changed which allows monitoring of all lines by LED's which also helps in seeing what is going on. It may be a long, hard slog, but most debugging can be.

And don't forget the number one rule when debugging; don't get overly frustrated, put it to one side and come back to it later.
 

Michael 2727

Senior Member
I'll make a list, it might be easier that way.
1.
I only use 08Ms at present, I like them, smaller is better, I may try the others one day but don't have the need just yet.
2.
The latest code I had been playing with is the one frankeltham posted, but so far no
joy. I know my setup is probably spitting out something from watching the O/P Led.
But what who knows,I'll refer to that later.
3.
Stan, the DSB1820s are great I am having a lot of fun with them, almost as much as the
picaxe driving it. If you have a copy of SC Nov 2000, Programmable electronic thermostat.
I wrote that article, I have an abundant supply of those little suckers left over. I was trying
to think of something usefull do do with them, I don't like seeing things go to waste. At present
I think the DS1620 has been replaced now by the DS1627/DS1727, still backward compatible.
At the moment I only wanted a display function but may look into a picaxe programmer later.
4.
Andy, (1) I thought about what many have recently said and what I have personally found to
be the case about trying to sort out FAQs and scattered information and regurgitation.
I thought having the actual content only on one page and the comments on another may help but
it doesn't seem to be turning out that way. Now you know what not to do.
Every day new members will arrive and ask the &quot;same ol same ol&quot;, but we all were there once.
I have only been here since Sep 2005 myself, so anything before that I have missed and searching
does not always give the expected results or any of the insight from actually following a thread
through to completion.
4(2)
The art of teaching is a fine thing, some are better than others at imparting knowledge from one
mind to another, and everybody has their own opionion. I take the approach if they even bother
to ask then half the battle is won. I would rather give a detailed boring full explanation of something
rether than let people stumble in the dark, if informatoin is only given out like feeding bread crumbs
to seaguls, you may lose your audience and only end up with a bunch of brid brains.
That's only my opinion, Electronics needs all the new hobbyists it can get or run the risk of suppliers
closing down the domestic industry through the lack of demand. It is happening as we speak.

I am not an electronics person by trade, in fact a Sheet Metal worker 1st Class, which I have not done
for many years. Until 2001 I had never had a lesson in electronics, I took up Cert II in Electronics or
the BEC equivalent back then. Everything I know is from magazines and building kits from the age of
15. I have had many years experience in electronics though e.g. IBM assembly/laptop repairs, ARMY
sublet electronics contractor, Security intallations, to name a few.

But when it comes to timing protocols, handshaking and Comms etc, I need all the help I can get.

I am getting older and yes it hard for an old dog to learn new tricks, it will happen to you all one day.
I have a lot of experience which I am quite willing to share, just ask. And I am to old to be a seagul.

I don't have any equipment or computer apps to monitor Comms etc, and I don't really whish to
proceed down that path, but you never know.

Using an 08M only, v v v v v v
I missed the bit about the 1k on the Output, I wasn't here that day. what when where please.
I have had several attempts left it and come back.
Conflict 1,,,,, some information suggests bidirectional I/O changing code to make pin &quot;input&quot;
could someone please clarify this. Do I need 1 or 2 pins for data transfer ?

Using the code below that frank posted was the last one I think I tried some weeks ago.
http://www.parallax.com/dl/docs/prod/appkit/ds1620Thermometer.pdf

My setup is as follows,
08M
Pin 0 to DS Clock
Pin 1 to DS Reset
Pin 2
Pin 3
Pin 4
The DS1620 has one data I/O pin, DQ.
How should I configure this, please include any pullup/down/across
comopnents. Using the above code.

Thank You,
Michael.


Edited by - Michael 2727 on 1/17/2006 1:47:18 AM
 

premelec

Senior Member
I notice an ad on the back of an electronics magazine I just got that the 'latest' units are the DS1621 and DS1631 in tiny 8 pin packages.... data sheet at www.maxim-ic.com could provide a day of entertaining reading :)

I2C protocol and far out timing diagrams - I too am getting old... On I2C lines pull up
resistors are required - I use them to get out of my chair as well :)

Digikey lists these for less than $3US so Stan can put one on each classroom chair economically and see if he's keeping them warmed up!
 

andrewpro

New Member
Hmm..still confused as to where I'm supposed to be ptting this, feel free to move it to whichever one it belongs ;)

Looking at the &quot;3 wire interface&quot;, youd think SPI at first, but ti's not quite.

As far as timing diagrams go, it's the key to figuring this whole thing out. The data gets clocked IN on the rising edge, and OUT on the falling edge. Sounding alot like SPI so far, but theres a catch. Theres only two lines!! Argh. Feel free to bang heads now.

To understand the SPI protocol (not saying you dontm but jsut in case) I have a basic tutorial on my website:

<A href='http://research.plistin.com/picaxe/picaxeSPI.html' Target=_Blank>External Web Link</a>

This fits if your using three wires, clock and separate in and out, but theres a little trick, using that information, that will make the interfacing simpler in this case.

The chip, in essence, follows the SPI protocol. And, using an 08M makes your life even easier, actually. The key is the data clocking...out on the rising edge, (form the picaxe), and in on the falling edge (in to the picaxe). Since you control the clock with bit banging, all you do is this:

1: Put your command byte into b0
2: make your DQ an output.
3: Make DQ (on the picaxe) equal to bit0.
4: Make the clock line high.
5: While the clock line is high, make the DQ low, and make it an input.
6: Make the clock line low.
7: Take the low or high value from the DQ pin on the picaxe, and put it in, say, bit15.
8: divide W0 by 2. This kicks out the lsb of the command byte, puts the next command byte bit into it's place, moves the lsb of the incomming data down one space in the order, and opens up B15 again to recieve the new byte.
9: start all over until youve clocked all 9 bits out. What you will be left with is a word variable, W0, with 9 bits of data in it, giving you 8 bits (b0) and one sign bit (bit one of B1)

No guarantees, as I'm doing this from memory of a datasheet I skimmed over hours and hours ago, at least. And it's not code, but gives you the directions to understand what's happening within the bit banging. From that, you can extrapolate the actual bit banging code, and should figure it out pretty easily.

I hope that helps. If not, I can always try again ;)

--andy P
 

hippy

Technical Support
Staff member
This should give an idea of how to use a bit-banged device which has a single, bi-directional I/O line. It's a typical scenario with the diagram showing the last bit of some command to the chip being output, after which the chip will have data available which needs to be read back.

For an 08 and 08M interfacing can be two wire because the pin can be an input or output. For others, where pins are fixed input or output, it's necessary to use three lines.
<code><pre><font size=2> _______
Data Out to Chip -----|_______|-----------============-------
_______
Data In from Chip ---======================--|_______|-=======

.-------. .-------.
Clock to Chip | | | |
---------' `--------' `---------

PICAXE-08/M Solution
====================

PICAXE-08
.---------. Chip
| | .---------.
| I/O 1|&lt;-&gt;------------&lt;-&gt;| Di/Do |
| | | |
| Clk 2|-----------------&gt;| Clk |
| | `---------'
`---------'

SYMBOL DAT_PIN = 1 ' Data In/Out Pin
SYMBOL CLK_PIN = 2 ' Clock Out Pin
SYMBOL DAT_VAL = pin1 ' Data In Value on Pin1

LOW CLK_PIN ' Make Clock output, and low

OUTPUT DAT_PIN ' Make the pin an output

HIGH DAT_PIN ' The first data bit to send ( or LOW DAT )
HIGH CLK_PIN ' Clock the bit into the chip
LOW CLK_PIN ' Clear the clock
:
repeat until all bits sent out
:
HIGH DAT_PIN ' The last data bit to send ( or LOW DAT )
HIGH CLK_PIN ' Clock the bit into the chip
LOW CLK_PIN ' Clear the clock

INPUT DAT_PIN ' Make the pin an input, so we raed from it

HIGH CLK_PIN ' Clock the bit out of the chip
bit0 = DAT_VAL ' Read the data from chip
LOW CLK_PIN ' Clear the clock
:
repeat until all bits read in
:
HIGH CLK_PIN ' Clock the bit out of the chip
bit7 = DAT_VAL ' Read the data from chip
LOW CLK_PIN ' Clear the clock


Other PICAXE Solution
=====================

.---------.
| |
| In I1|&lt;----------. Chip
| | ___ | .---------.
| Out O1|---|___|---^---&lt;-&gt;| Di/Do |
| | 1K0 | |
| Clk O2|-----------------&gt;| Clk |
| | `---------'
`---------'

SYMBOL OUT_PIN = 1 ' Data Out Pin
SYMBOL CLK_PIN = 2 ' Clock Out Pin
SYMBOL DIN_VAL = pin1 ' Data In Value on Pin 1

LOW CLK_PIN ' Clock is normally low

HIGH OUT_PIN ' The first data bit to send ( or LOW OUT )
HIGH CLK_PIN ' Clock the bit into the chip
LOW CLK_PIN ' Clear the clock
:
repeat until all bits sent out
:
HIGH OUT_PIN ' The last data bit to send ( or LOW OUT )
HIGH CLK_PIN ' Clock the bit into the chip
LOW CLK_PIN ' Clear the clock

LOW OUT_PIN ' Make the output low so a read can be done

HIGH CLK_PIN ' Clock the bit out of the chip
bit0 = DIN_VAL ' Read the first data bit from chip
LOW CLK_PIN ' Clear the clock
:
repeat until all bits read in
:
HIGH CLK_PIN ' Clock the last out of the chip
bit7 = DIN_VAL ' Read the first data bit from chip
LOW CLK_PIN ' Clear the clock
</font></pre></code>
 

Technical

Technical Support
Staff member
Using output0 as the clock would not be a good idea. Every time you do a debug or download the DS chip will receive lots of spurious clock signals (as that pin is also the serial download tx pin) that could disrupt the DS chip. Use a different pin as Hippy suggests in his diagram.
 
Top