2017-01-09 12:35 PM
Hello,
i have a bldc motor with hall sensors, each hall sensor is conected to PA0 PA1 PA2 which coresponds to CH1,2,3 of timer2.
So in my gpio init routine i have declared the gpio's as following
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 |GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;GPIO_Init(GPIOA, &GPIO_InitStructure);GPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_AF_TIM2);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_TIM2);GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_TIM2);And somewhere in the timer2 cc1 irq handler i want to read the bit order of the 3 hall sensors.
i was thinking ading something like this uint16_t pdata = GPIO_ReadInputData(GPIOA) & 0x0007
But i read some unusual values.
Do i need another mode for GPIO in order to read the corect data? i was thinking of using GPIO_Mode_IN , but in this case will i am able to trigger the timer2 ?
2017-01-09 12:41 PM
You should be able to read the GPIOx->IDR in all modes except Analogue In, which turns of the Schmitt Trigger on the input.
2017-01-09 02:40 PM
Hello Clive,
Thanks for the information. After seeing this, i was concerned about framing errors on USART.... i keep forgeting to check the stm32f4xx.h file.... i was having HSE_VALUE 25 MHZ , and my discovery board has 8MHZ ... anyway... redefined the PLL settings and HSE valyue, and the USART behaves normal, i can see the corect data from the hall GPIO inputs (hall3 is MSB)