Jump to content
43oh

1-Wire Reset Command sample code


Recommended Posts

Hi Guys,

 

So, after calibrating the 16Mhz DCO using my code (Here's a link. It's below NatureTM's code), I have a rock solid 16MHz DCO.

 

Now I can create a reliable 1us delay routine that is required for proper 1-Wire interfacing. Here's an article that shows you the desired waveforms.

 

By the way, Touch tried porting the Arduino 1-Wire code to the Launchpad without success. The reason why it failed is due to the fact that the Arduino runs at 16MHz and the stock Launchpad board runs at 1MHz.

 

Here's my code that I used to generate an inverted version of the 1-Wire Reset command on P1.1 of the Launchpad.

 

//******************************************************************************
//  MSP430G2xx1 Demo - Basic Clock, Output Buffered SMCLK, ACLK and MCLK/10
//  modified to create a One Wire reset pulse train on P1.1
//
//  Description: Buffer ACLK on P2.0, default SMCLK(DCO) on P1.4 
//
//  ACLK = LFXT1 = 32768, MCLK = SMCLK = DCO set to 16MHz after calibrating it.
//
//  External watch crystal installed on XIN XOUT is required for ACLK  
//
//               MSP430G2xx1
//             -----------------
//         /|\|              XIN|-
//          | |                 | 32kHz
//          --|RST          XOUT|-
//            |                 |
//            |       P1.4/SMCLK|-->SMCLK = Default DCO
//            |             P1.1|-->MCLK/10 = DCO/10
//            |        P1.0/ACLK|-->ACLK = 32kHz
//
//  J. Voth
//  Nine Micron
//  January 2011
//  Built with CCS Version 4.2.1
//******************************************************************************

#include 

#define delayMicroseconds(n) __delay_cycles(n<<4)

void main(void)
{
 WDTCTL = WDTPW + WDTHOLD;                 // Stop Watchdog Timer

 BCSCTL1 = CALBC1_16MHZ;                   // Set range
 DCOCTL = CALDCO_16MHZ;                    // Set DCO step + modulation

 P1DIR |= 0x1F;                            // P1.0,1,2,3 and P1.4 outputs
 P1SEL |= 0x11;                            // P1.0,4 ACLK, SMCLK output

 while(1)
 {
   // drive P1.1 high for ~480us
   P1OUT |= 0x02;  // activate output
   delayMicroseconds(480);

   // drive P1.1 high for ~480us
   P1OUT &= ~0x02; // deactivate output

   // pulse p1.2 high for 70us
   P1OUT |= 0x04;  // activate P1.2 output
   delayMicroseconds(70); 

   P1OUT &= ~0x04; // deactivate P1.2 output

   // Do nothing for the remainder of the time slot
   delayMicroseconds(410);
 }
}

 

I modeled it on the Basic Clock Demo program from TI because you can scope the DCO/MCLK frequency on P1.4 as a sanity check. If your DCO isn't calibrated then a scoping of P1.4 will make that plain to you.

 

I also generate a 70us pulse on P1.2 because that is how long you have to wait until reading the 1-Wire bus for a response.

 

To properly make use of this code, the 1-Wire bus interface will have to be a two pin version. The addition of a transistor (or FET) will invert the TX signal and thus make everything okay.

 

Take a look and tell me what you think.

Link to post
Share on other sites
That's neat. I tried some thing like that but I ended up implementing it in hardware. A line driver if you will

I thought that's what we're doing here - implementing it in hardware? MSP hardware!

 

It's one thing to use an FPGA or one of Maxim's dedicated parts to do all the timing but they add $$'s to your overall BOM costs. And they cause you to solve different engineering problems ie: I/O pin allocation, communication bus design, board space allocation, higher current consumption, clocking requirements, etc.

 

Any time you can take one part out of your BOM then you are saving money. Big money if you're gonna be a "Big Playa" and make 100's of your devices.

 

An G2231 is still only <$1 in 1K quantities. How much does a Xilinx FPGA cost? Or a DS2480B? To me, it makes sense to spend some time to make the g2231 do the job and put those $$'s back in my pocket!

 

Here's a link to a Maxim document discussing all the 1-Wire Master options.

Link to post
Share on other sites

lol I actually had like a much of logic gates and flip flops which is worse than what you suggest lol. the challenges was not to use a micorcontoller. Its nice to see a software solution though. I might actually use this to communicate with the Game Cube in a project of mine

Link to post
Share on other sites

Ooooh... You meant hardware as in TTL gates.

 

I see.

 

Sir, You are a masochist.

 

Unless you meant using TTL gates inside a CPLD. Then you're a university student looking for extra marks. :D

 

Be honest. Which is it? Student or Masochist?

Link to post
Share on other sites

LOL. Actually a friend challenged me to make a nes to game cube converter that had no micro controllers. I got it some what working thought I had the help of a basic stamp to decode the command and preset some shift registers at start up. I eventually gave up when my EX girl friend threw some crap on my bread board. As I clear the stuff I started finding a some loose wires.

 

I have all ways enjoyed building this with ttl chips and design it in paint

Link to post
Share on other sites
  • 6 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...