cancel
Showing results for 
Search instead for 
Did you mean: 

1Wire Driver implementation using STM32 Timer

Ghada Dhibi
Associate II
Posted on April 10, 2017 at 11:50

Hello, 

I'm using STM32L486 microcontroler and I have to implement eeprom 1Wire driver (DS2431). 

As first implementation, I used _NOP operation to generate 1�s Delay. 

It was working correctely and I was able to write and read data from my 1Wire eeprom. 

As a second step, and to avoid using _NOP instrcution, I have to implement TimeBase timer example to generate 1Wire delays. 

For example, to reset my eeprom bus, I have to implement timer using state machine as follow: 

1. Set 1Wire GPIO to low level.

2. Program TimeBase to generate Interrupt after 500�s

3. In timer Call back: (after 500�s)

  1. Stop the timer 
  2. Configure GPIO to input mode
  3. re-configure timer for 70�s interrupt generation.

4. In timer call back (after 70�s) 

  1. Stop the timer 
  2. Read the input pin
  3. re-configure timer for 420�s interrupt generation.

5. 

In timer call back (after 420�s)  

  1. Stop the timer.

  2. State ready is set: 1wire is ready to read or write operation. 

Unfortunately, reset pulse is not working correctly due to my implementation. and I am asking for re-configuring timebase on timerCall back function as follow : 

void TIM1_UP_TIM16_IRQHandler (void)

{

/* Check whether update interrupt is pending */

if(LL_TIM_IsActiveFlag_UPDATE(TIM1) == 1)

{

/* Clear the update interrupt flag*/

LL_TIM_ClearFlag_UPDATE(TIM1);

}

/* TIM1 update interrupt processing */

DRV_1Wire_TimerCallBackLL();

}

void DRV_1Wire_TimerCallBackLL(void)

{

LL_TIM_DisableIT_UPDATE(TIM1);

LL_TIM_SetAutoReload(TIM1, xxx);  // depending on my state machine 

LL_TIM_EnableIT_UPDATE(TIM1);

IncrementStateMachine();  // wait for the next state 

}

So my questions are: 

1. Can I Re-configure my timer period on Timer call back function ? 

2. How can I reduce more and more my timer period configuation? 

3. there is better solution to calculate period on �s delay without using While instruction? 

thnx. 

#1wire #stm32l4-timer
2 REPLIES 2
Uwe Bonnes
Principal III
Posted on April 10, 2017 at 12:24

You can use a 2-channel timer. One channel will generate the waveforem, the other channel captures the rising edge. Nut/OS

https://svn.code.sf.net/p/ethernut/code/trunk

uses this approach in nut/arch/cm3/dev/stm/stm32_owitim.c.

Lecordier.Guy
Associate III
Posted on April 11, 2017 at 11:13

Hello,

 Do you know this application note 214 from Maxim:

https://www.maximintegrated.com/en/app-notes/index.mvp/id/214

' Using a UART to Implement a 1-Wire Bus Master '

 I used this from a STM32F429 to DS2431

 Regards