STM32F103c8 timer

Share code examples or discuss embedded software, including device drivers, interrupt handlers, middleware and application code.

Moderators: Markus Girdland, Mattias Norlander

partha_nayani
Posts: 18
Joined: Tue Nov 29, 2016 12:01 pm

STM32F103c8 timer

Postby partha_nayani » Fri Mar 17, 2017 4:13 am

Hi all,
After a successfully getting the serial port to work, I am now stuck with timer problem. Spent enough time before coming here for help. I want to toggle PA6 pin, ch1 of timer3. After a lot of trials I tested on STM32F103RCT6 (different timer and pin) and found the code working on that controller. With only changes to timer3 and toggle pin, the code is not working on C8 controller. I have posted my init code below. I am reading the timer counter and sending the content to serial port, in my main loop and I notice the timer counter running. The only issue is with the pin toggle.

Code: Select all

void tim3_init (void)
{
   TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
   TIM_OCInitTypeDef  TIM_OCInitStructure;

     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;

     GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_6;      // tim3 channel 1 output
     GPIO_Init(GPIOA, &GPIO_InitStructure);

       /* Time base configuration */
       TIM_TimeBaseStructure.TIM_Period = 665;
       TIM_TimeBaseStructure.TIM_Prescaler = 2;    //(uint16_t) (SystemCoreClock / 24000000) - 1;
       TIM_TimeBaseStructure.TIM_ClockDivision = 0;
       TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

       TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);      //  this should start running the timer2

       TIM_Cmd (TIM3, ENABLE);
       TIM3->EGR = 1;
       TIM3->CCER |= TIM_CCER_CC1E;
        TIM3->CCER &= (uint16_t)~((uint16_t)TIM_CCER_CC1P);

       TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Disable);

       /* PWM1 Mode configuration: Channel1 */
//       TIM_OCInitStructure.
       TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
       TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
       TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
       TIM_OCInitStructure.TIM_Pulse = 0;

       TIM_OC1Init(TIM3, &TIM_OCInitStructure);
//       TIM_CtrlPWMOutputs(TIM3, ENABLE);

}



Awaiting your help. Thanks.

anniehall
Posts: 2
Joined: Wed Oct 18, 2017 12:03 pm

Re: STM32F103c8 timer

Postby anniehall » Wed Oct 18, 2017 12:30 pm

Thanx for that code!
I like this forum. Thanks for it!

frank_ee
Posts: 62
Joined: Wed Apr 05, 2017 5:08 pm
Location: USA

Re: STM32F103c8 timer

Postby frank_ee » Fri Oct 20, 2017 6:56 pm

You should use the STMCubeMX code generator to initialize the timer. It looks like an timer initialization problem.

RaviDhoble
Posts: 1
Joined: Thu Dec 21, 2017 3:20 pm

STM32F103C8 Serial Communication using TrueStudio

Postby RaviDhoble » Wed Dec 27, 2017 9:07 am

Hello Partha,

Referring to your post related to the STM32F103C8 controller, I need some help to understand code execution on this controller. I am a complete newbie to ARM controller and Architecture.
So to start with first, I bought STM32F103C8T6 controller board. I followed this link https://www.techshopbd.com/uploads/prod ... inoguide(1).pdf to understand the working and as beginner reference document.

I followed all the steps mentioned in this link to communicate with the STM32F103C8 controller using an FTDI chip and Arduino. After that, I have also flashed the DFU firmware into the controller to upload code via direct USB COM without an FTDI. It worked too. Not a problem here.

Arduino is a good platform and easy way to upload and test basic codes but not the standard way to develop ARM software. So, I decided to switch to TrueStudio for more professional development but haven't written any C code for this ARM controller yet but I was trying to upload basic example code to this controller.

So here I want to understand how to start with developing projects for this controller board? Can you provide any link to start with? I am still learning about the features in TrueStudio.

Another part is, Once i build the project with generated binary hex file, How to upload code in STM32F103C8? Here am not using ST-LINK or any other programmer or debugger hardware yet.

As I can see the COM port assign to this board in windows device manager (because of DFU firmware in STM32), How I make sure that the code is uploaded to target controller using TrueStudio?


Return to “Embedded target code development discussions”

Who is online

Users browsing this forum: No registered users and 1 guest