I'm working on a project where I need to set up two encoders.
I use included timers as timer encoder.
encoder 1 is configured on GPIO PB7/PB6
encoder 2 is configured on GPIO PB5/PB4
In order to isolate the mistake (hardware/software), here is what I tried:
- First, only 1 encoder wired to the board, only 1 timer configured on my board/code, on GPIO PB7/PB6:
- encoder 1 on PB7/PB6: working fine
- encoder 2 on PB7/PB6: working fine
- So hardware seems to be bine
- Then I modify my test code, I kept same code excepted I changed PB7/PB6 for PB5/PB4
- encoder 1 on PB5/PB4: not working
- encoder 2 on PB5/PB4: not working
What is really strange and I don't understand:
In case scenario 2, if I put encoder 1 on PB7/PB6 and encoder 2 on PB5/PB4, only PB5/PB4 are initialized in my sketch, encoder 2 is not working but encoder 1 on PB7/PB6 is working.
I'm using STD Periph lib, STM32F103 and Keil
here is my simple test code
// Initialize LCD
// Step 1: Initialize GPIO as input for rotary encoder
// PB7 (TIM4_CH2) (encoder pin A), PB6 (TIM4_CH1) (encoder pin B)
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPD;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
// Step 2: Setup TIM4 for encoder input
TIM_EncoderInterfaceConfig(TIM4, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising,
// Get encoder value
enc_cnt = TIM_GetCounter(TIM4);
// Print encoder value
sprintf(enc_cnt_buf, "%i", enc_cnt);
maybe answer is obvious but I can't find it.
Thank you for your help