AnsweredAssumed Answered

STM8S Cannot write to TIM2->CCMR

Question asked by depue.fraser on Apr 26, 2012
Latest reply on Apr 27, 2012 by depue.fraser
Hi, I have just recently started developing with the STM8S003F3P TSSOP20 device. I have been working through a number of peripherals, which have gone fine, but have now run into a roadblock. I am using the STVD with Raisonance toolset. 

What I am trying to do is get 2 PWM signals on the pins 1 and pin 20, that is TIM2_1 and TIM2_2. I noticed right off the bat that when using the firmware libraries, the PWMs didnt come up, so i tried to do a few different implementations and none seem to be able to make the PWMs go. So after investigating the address values for the configurations (located at base address 0x5300) i noticed that CCMR1 and CCMR2 are not getting set at all. These are at location 0x5305 and 0x5306. Even when i set the values directly and step through, right after the instruction completes, the value at those addresses remain unchanged. I thought the chip might be faulty so i tried it on a few different ones and all the same result. So im officially stuck and need help. I am wondering if anyone has seen this or knows what I am doing wrong.

The chip is functioning correctly because on the same device, (same setup etc) i have been able to get SPI and the EncoderMode on TIM1 functioning perfectly. It just seems to be TIM2 that wont let me configure correctly. 

Two example implementations i have done are as follows....

addresses defined:

#define mCCMR1 (*((vu8 *) (0x5305)))
#define mCCMR2 (*((vu8 *) (0x5306)))
#define mCR1 (*((vu8 *) (0x5300)))

and then in main i have:

     TIM2->PSCR = 0x00;
     TIM2->ARRH = 0x03;
     TIM2->ARRL = 0xE7;
     
     TIM2->CCR1H = 0x01;
     TIM2->CCR1L = 0xF4;
     TIM2->CCR2H = 0x01;
     TIM2->CCR2L = 0xF4;
     TIM2->CCER1 = 0x33;
     mCCMR1 = 0x68;
     mCCMR2 = 0x68;
     mCR1 = 0x01;


In this version, CR1 gets sets correctly but CCMR1 and CCMR2 do not, they remain at zero.

Another implementation was:

     TIM2_DeInit();
     TIM2_TimeBaseInit(TIM2_PRESCALER_1, 999);
     
     //Channel 1 - IN1
     TIM2_OC1Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE,CCR1_Val, TIM2_OCPOLARITY_LOW);
  TIM2_OC1PreloadConfig(ENABLE);


  //Channel 2 - IN2
  TIM2_OC2Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE,CCR2_Val, TIM2_OCPOLARITY_LOW);
  TIM2_OC2PreloadConfig(ENABLE);
     
     TIM2_ARRPreloadConfig(ENABLE);
     TIM2_Cmd(ENABLE);

and the same result happens here, all the configuration registers seem to get written appropriately except for CCMR1 and CCMR2.

Any input at all would be helpful, thank you in advance!!

Outcomes