/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / 1-wire

Username:     
Password:     
             

Forum

# 1   2009-05-09 14:41:52 1-wire

logictechs
Member
Registered: 2009-05-07
Posts: 68

1-wire

Hi,

I was wondering if anyone has Dallas 1-wire code example for the Primer 2.

Thanks!

Offline

 

# 2   2010-10-11 14:52:37 1-wire

crowse
New member
Registered: 2010-07-11
Posts: 5

Re: 1-wire

Hi Logictechs,

Did you ever manage to get the 1-wire protocol working? If so, I would much appreciate knowing how you did it. i..e were you able to use a USART or did you need to bit bang.

I want to use a Parallax IR temperature sensor, and their doc seems similar to 1-wire.

Chris

Offline

 

# 3   2010-10-12 01:30:21 1-wire

logictechs
Member
Registered: 2009-05-07
Posts: 68

Re: 1-wire

Hi Chris,

Yes I was able to with the help of a logic analyser.  I used the bit bang method to do so.  Because of the critical timing, I suggest using a logic analyser to help you get your code right.  Really eases the development.  I may post the code I created here.  Trying to get a product released based on the code and the Primer2. 
I first tried to use the I2C 1-wire driver chip from Maxim but couldn't get that to work right.  Less cost using the bit bang method.  Strange thing I discovered is I didn't need a pullup resistor.  When I added it, it didn't seem to toggle at all.  I used the pullup code to enable the pin and seems to work fine.

Good luck,

Logictechs

Offline

 

# 4   2011-02-28 10:45:30 1-wire

bombiens
New member
Registered: 2010-05-26
Posts: 1

Re: 1-wire

Hi Logictechs,

can you send me your 1-wire code?
I have difficulties with the delays on the Bus, so it would be nice if you could help me.
Soenke

Offline

 

# 5   2011-03-01 01:21:11 1-wire

logictechs
Member
Registered: 2009-05-07
Posts: 68

Re: 1-wire

Here's a library I made.  Need to set your speed to medium before using the functions.  Be sure to make note of the pin used.  Also need to disable tim2.  I've made other functions for the various temperature and Thermochron series buttons.  Let me know if you need further assistance.

owirelib.h

void delay1(int);
unsigned char ow_read_bit(void);
void ow_write_bit(unsigned char bitval);
unsigned char ow_read_byte(void);
void ow_write_byte(unsigned char val);
unsigned char ow_reset(void);
void ow_pin_out(void);
void ow_pin_in(void);
void ow_get_rom(unsigned char *romid);

GPIO_InitTypeDef GPIO_InitStructure;


owirelib.c

#include "stm32f10x_conf.h"
#include "stm32f10x_it.h"
#include "owirelib.h"

int i;
void delay1 (int time)
{

    time *= 10;
    for(i = 0; i < time; i++)
        asm volatile ("nop");
}

unsigned char ow_reset(void)
{
u8 presence;
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_RESET);
delay1(224); // delay 560uS
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_SET);
ow_pin_in();
delay1(14);
presence = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_4);
presence &= 0x01;
ow_pin_out();
return(presence);
}

unsigned char ow_read_bit(void)
{
unsigned char i;
unsigned char val;
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_RESET);
delay1(3);
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_SET);
ow_pin_in();
delay1(4);
val=GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_4);
ow_pin_out();
val &= 0x01;
delay1(18);//was 38
return (val);
}

void ow_write_bit(unsigned char bitval)
{
if (bitval)
{
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_SET);
delay1(1);//was 11
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_RESET);
delay1(11);//was 16
}
else
{
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_SET);
delay1(22); //was 16
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_RESET);
}
}

unsigned char ow_read_byte(void)
{
unsigned char i;
unsigned char value=0;
for (i=0;i<8;i++)
{
if(ow_read_bit()) value |= (0x01<<i);
delay1(25); //was 65
}
return(value);
}

void ow_write_byte(unsigned char val)
{
u8 a;
u8 temp;

for(a=0;a<8;a++)
{
temp = val >> a;
temp &=0x01;
if (temp)
{
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_RESET);
delay1(2);
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_SET);
delay1(26);//was 26
}
else
{
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_RESET);
delay1(20);  //was 15
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_SET);
}
delay1(2);
}
delay1(65); //was 65
//GPIO_WriteBit(GPIOC, GPIO_Pin_5, Bit_SET);
}

void ow_pin_out(void)
{

/* Configure CX_ADC2 as 1-wire port */
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
   GPIO_Init(GPIOA, &GPIO_InitStructure);   
   GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_SET);
}

void ow_pin_in(void)
{
 
/* Configure CX_ADC2 as 1-wire port */
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
   GPIO_Init(GPIOA, &GPIO_InitStructure);     
}

void ow_get_rom(unsigned char *romid)
{
    ow_write_byte(0x33);
    for(i = 0; i < 8; i++)
       {
           romid[i] = ow_read_byte();                     
       }       
}

Offline

 

# 6   2013-01-25 08:32:55 1-wire

ArFa
New member
Registered: 2013-01-25
Posts: 1

Re: 1-wire

logictechs :

Here's a library I made.  Need to set your speed to medium before using the functions.  Be sure to make note of the pin used.  Also need to disable tim2.  I've made other functions for the various temperature and Thermochron series buttons.  Let me know if you need further assistance.

owirelib.h

void delay1(int);
unsigned char ow_read_bit(void);
void ow_write_bit(unsigned char bitval);
unsigned char ow_read_byte(void);
void ow_write_byte(unsigned char val);
unsigned char ow_reset(void);
void ow_pin_out(void);
void ow_pin_in(void);
void ow_get_rom(unsigned char *romid);

GPIO_InitTypeDef GPIO_InitStructure;


owirelib.c

#include "stm32f10x_conf.h"
#include "stm32f10x_it.h"
#include "owirelib.h"

int i;
void delay1 (int time)
{

    time *= 10;
    for(i = 0; i < time; i++)
        asm volatile ("nop");
}

unsigned char ow_reset(void)
{
u8 presence;
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_RESET);
delay1(224); // delay 560uS
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_SET);
ow_pin_in();
delay1(14);
presence = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_4);
presence &= 0x01;
ow_pin_out();
return(presence);
}

unsigned char ow_read_bit(void)
{
unsigned char i;
unsigned char val;
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_RESET);
delay1(3);
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_SET);
ow_pin_in();
delay1(4);
val=GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_4);
ow_pin_out();
val &= 0x01;
delay1(18);//was 38
return (val);
}

void ow_write_bit(unsigned char bitval)
{
if (bitval)
{
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_SET);
delay1(1);//was 11
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_RESET);
delay1(11);//was 16
}
else
{
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_SET);
delay1(22); //was 16
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_RESET);
}
}

unsigned char ow_read_byte(void)
{
unsigned char i;
unsigned char value=0;
for (i=0;i<8;i++)
{
if(ow_read_bit()) value |= (0x01<<i);
delay1(25); //was 65
}
return(value);
}

void ow_write_byte(unsigned char val)
{
u8 a;
u8 temp;

for(a=0;a<8;a++)
{
temp = val >> a;
temp &=0x01;
if (temp)
{
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_RESET);
delay1(2);
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_SET);
delay1(26);//was 26
}
else
{
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_RESET);
delay1(20);  //was 15
GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_SET);
}
delay1(2);
}
delay1(65); //was 65
//GPIO_WriteBit(GPIOC, GPIO_Pin_5, Bit_SET);
}

void ow_pin_out(void)
{

/* Configure CX_ADC2 as 1-wire port */
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
   GPIO_Init(GPIOA, &GPIO_InitStructure);   
   GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_SET);
}

void ow_pin_in(void)
{
 
/* Configure CX_ADC2 as 1-wire port */
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
   GPIO_Init(GPIOA, &GPIO_InitStructure);     
}

void ow_get_rom(unsigned char *romid)
{
    ow_write_byte(0x33);
    for(i = 0; i < 8; i++)
       {
           romid[i] = ow_read_byte();                     
       }       
}

Can you post a code for stm8 as one wire slave ?

Offline

 

Board footer