2020-03-16 09:08 PM
Hi,
Im trying to resurrect this project from 2015 (Software AWD control for RC Cards using 4x brushless motors):
https://github.com/hammerfet/BrinirController
Ive built his VS2013 solution and got all that side working fine. However, next is to determine I can read the RC Radio signal (standard RC drone Turnigy 9x and FRSky V8FR-II receiver) and Im getting problems. The signals are just two, throttle and steering and connected to PA0 and PA1 on a STM32 F407 discovery.
Sometimes it doesnt read anything, sometimes it reads it once occasionally it reads everything fine.
Here is the IO code:
/* TIM2 Init - PPM Inputs */
htim2.Instance = TIM2;
htim2.Init.Prescaler = PPMMEASUREPRESCALER;
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
htim2.Init.Period = 65535;
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
HAL_TIM_Base_Init(&htim2);
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig);
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig);
HAL_TIM_Base_Start_IT(&htim2);
and some more references in config.h:
#define PPMMEASUREPRESCALER 4
#define RECEIVERMINSIGNAL 500
#define RECEIVERMIDSIGNAL 25000
#define RECEIVERMAXSIGNAL 34000
Is there anything obviously wrong here? Anything I should know about connecting RC Radio PWM to the F407?
2020-03-16 11:19 PM
Timers have a PWM input "mode" - use it. Read the timer chapter in RM.
JW
2020-03-21 02:31 AM
Right, read the chapter, looked at the code and tried every combo of modes.
Here is the default:
GPIO_InitStruct.Pin = REC1PIN | REC2PIN | FB1PIN | FB2PIN | FB3PIN | FB4PIN;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(RECPORT/*same as FBPORT*/, &GPIO_InitStruct);
REC1 and 2 are PA0 and PA1 on TIM2.
As I said, it works sometimes (5% of the time) and when its displaying anything than zero it seems to just capture the first reading then stops.. but again not 100% of the time. Is there a time out or something?
2020-03-21 03:49 AM
I don't understand what exactly you do and I don't use Cube, but maybe you should try to adopt the example from [STM32Cube_FW_F4_Vxxxx]\Projects\STM32F4-Discovery\Examples\TIM\TIM_PWMInput\
JW
2020-03-21 09:50 PM
Well, now read the GPIO chapter, especially the alternate function configuration. =)
2020-03-21 11:48 PM
Yep, did that too, replicated all the GPIO modes from [STM32Cube_FW_F4_Vxxxx]\Projects\STM32F4-Discovery\Examples\TIM\TIM_PWMInput\.
No difference, generally doesnt read anything TBH once I deviate significantly from the original code (which again, Ive replicated the HW used and should work?). Sadly this is taking way too much time, I can connect and get responses on a Raspberry Pi, just have to accept loosing that guys several years of mathematics and configuration tuning if I go that route.
2020-03-22 12:47 AM
The GPIO configuration you showed does not configure those pins for timer input channels!
Have you looked at this file at all?
2020-03-22 03:07 AM
Yes I have looked at that file, though that project uses different timers configured quite differently.
On the GPIO Pins not being for the right timer input channel, how are you telling that?
A file called io.c defines REC1PIN and REC2PIN and RECPORT as:
/* Receiver input channel pins */
#define REC1PIN GPIO_PIN_0
#define REC2PIN GPIO_PIN_1
#define RECPORT GPIOA
/*Configure GPIO input pins */
GPIO_InitStruct.Pin = REC1PIN | REC2PIN | FB1PIN | FB2PIN | FB3PIN | FB4PIN;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(RECPORT/*same as FBPORT*/, &GPIO_InitStruct);
.....
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
{
if(htim_base->Instance==TIM2)
{
/* Peripheral clock enable */
__TIM2_CLK_ENABLE();
/* Peripheral interrupt init*/
HAL_NVIC_SetPriority(TIM2_IRQn, PPM_INPUT_PRIORITY, PPM_INPUT_TIM_SUBPRIORITY);
HAL_NVIC_EnableIRQ(TIM2_IRQn);
My config.h :
/* Receiver input channel pins */
#define REC1PIN GPIO_PIN_0
#define REC2PIN GPIO_PIN_1
#define RECPORT GPIOA
2020-03-22 10:09 PM
I'm not saying that pins aren't connected to the right timer, but that they aren't connected to any timer at all. I've said to look for GPIO configuration. "Alternate function" are not a fancy words for nothing. I've shown you a file where that's done. In that file there are only 13 lines of code. That is pure spoon-feeding, but you still can't see the difference compared to your configuration? You cannot write code with such a superficial attitude to details!
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Alternate = GPIO_AF_TIMx;
Can you spot it now?
2020-03-23 02:11 AM
Sadly Im not following you. I have tried all sorts of combos, as you can see by my commenting out below:
/*Configure GPIO input pins */
GPIO_InitStruct.Pin = REC1PIN | REC2PIN | FB1PIN | FB2PIN | FB3PIN | FB4PIN;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
// GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
// GPIO_InitStruct.Speed = GPIO_SPEED_MEDIUM;
GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
HAL_GPIO_Init(RECPORT, &GPIO_InitStruct);
Bearing in mind the original stm32f4xx_hal_msp.c Im working from works 5% of the time and the linked PWM Example doesnt works at all. Im not even sure thats a good example to base off as Im specifically connecting a RC Radio controller (from a Drone, so its actually PPM) and the example is for more generic PWM stuff, of a different frequency.