Send data with one wire protocol?

Thread Starter

ArFa

Joined Apr 24, 2011
9
Hi there,
I want to send data through one wire protocol from stm8.
So, stm8 will act as one wire slave device, and send those data to another device through one wire protocol.

Please if you can, tell me how to solve this problem !
 

Thread Starter

ArFa

Joined Apr 24, 2011
9
Show what you are doing in order to send data.
Rich (BB code):
#include"stm8s.h"
#include <iostm8S105c6.h>
#include <intrinsics.h>
//#define cli() __asm("cli")
//#define rim() __asm("sim")

#define PR 0


//
//  Setup Timer 2 to generate an interrupt every 480 clock ticks (30 uS).
//

char A[64] = "1010101010101010101010101010101010101010101010101010101010101010"; // serial number to send to one wire
//int i ;
void SetupTimer2(char a) //40 us
{
    TIM2_PSCR = 0x00;       //  Prescaler = 1.
    if(a == 'r') // 
    {
      TIM2_ARRH = 0x04;       //  Wait for 480.
      TIM2_ARRL = 0x38;       
    }
    else if(a == 'p')
    {
      TIM2_ARRH = 0x01;       //  High byte of 120.
      TIM2_ARRL = 0x18;       
    }
    else if(a == 'b')
    {
      TIM2_ARRH = 0x00;       //  wait for 30us.
      TIM2_ARRL = 0x3c;       
    }
    else if(a == 'c')
    {
      TIM2_ARRH = 0x00;       //  wait for 10us.
      TIM2_ARRL = 0x14;       
    }

   // TIM2_IER_UIE = 1;       //  Turn on the interrupts.
    TIM2_CR1_CEN = 1;       //  Finally enable the timer.
}
//
//  Timer 2 Overflow handler.
//

#pragma vector = TIM2_OVR_UIF_vector
__interrupt void TIM2_UPD_OVF_IRQHandler(void)
{
    TIM2_SR1_UIF = 0;              //  Reset the interrupt otherwise it will fire again straight away.
    TIM1_IER_UIE = 0;
}

int i_count;
char proc_isr;
#pragma vector = 6
__interrupt void EXTI_PORTB_IRQHandler(void) // B interrupt
{
       //sim();
       //__disable_interrupt(); 
       PB_CR2 = 0x00; // disable EXTI_PORTB
       if(i_count<1)
       {
       SetupTimer2('r'); // delay_us(510);
       __enable_interrupt();
       __wait_for_interrupt();
       //__disable_interrupt();          
       PB_ODR_ODR4 = 0;//low -> presence
       PB_DDR = 0xff;
       
       SetupTimer2('p');//delay_us(140);
       
       __enable_interrupt();
       __wait_for_interrupt();
       }
       else
       if(i_count<9) // receive command from master -> 0xF0 search();
       {}
       else
       if(i_count<73) // go interrupt
       {
         if(A[i_count-8] == 0)
         {
           //send 0 bit
           PB_ODR_ODR4 = 0;//low -> bit
           PB_DDR = 0xff;
           SetupTimer2('b');//delay us = 60 us
           __enable_interrupt();
           __wait_for_interrupt();
           
           // send 1 bit
           PB_ODR_ODR4 = 1;
           PB_DDR = 0x00;
           SetupTimer2('b');//delay us = 60 us
           __enable_interrupt();
           __wait_for_interrupt();
         }
         else
         {
           // send 1 bit
           PB_DDR = 0x00;
           SetupTimer2('b');//delay us = 60 us
           __enable_interrupt();
           __wait_for_interrupt();

           // send 0 bit
           PB_DDR = 0xff;
           SetupTimer2('b');//delay us = 60 us
           __enable_interrupt();
           __wait_for_interrupt();
           
         }
         
           PB_DDR = 0x00;
           SetupTimer2('b');//delay 30us for recv signal.
           __enable_interrupt();
           __wait_for_interrupt();
       }
       i_count++;
       if(i_count>73)
         i_count = 0;
       //rim();
    PB_CR2 = 0x00;
}

//
//  Main program loop.
//
void main()
{
   i_count = 0;
   
   PB_ODR_ODR4 = 1;
   PB_DDR = 0x00; // porta D pin 4 input
   PB_CR1 = 0xff;         //  PB4 is pull-up input.
   PB_CR2 = 0xff;         //  PB4 is with interrupt
   EXTI_CR1_PBIS = 2;      //  Interrupt on falling edge.
   EXTI_CR2_TLIS = 0;      //  Falling edge only.
   __enable_interrupt();
    i_count = 0;
    while (1)
    {
      __wait_for_interrupt();
       PB_DDR = 0x00; // porta D pin 4 input
       PB_CR1 = 0xff;         //  PB4 is pull-up input.
       PB_CR2 = 0xff;
       EXTI_CR1_PBIS = 2;      //  Interrupt on falling edge.
       EXTI_CR2_TLIS = 0;      //  Falling edge only.
    }
}
 
Top