AnsweredAssumed Answered

1Wire Driver implementation using STM32 Timer

Question asked by Ghada Dhibi on Apr 10, 2017
Latest reply on Apr 11, 2017 by lecordier.guy.001

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. 

Outcomes