2014-09-08 01:25 AM
Hi,
In all examples I can find (ST Std driver library, STM32CubeF4, STM32CubeMX...) the CAN RX Pin is always configured regarding GPIO as Alternate Push/Pull Pin (Output) like the CAN TX Pin. I would expect the CAN RX pin to be configured as an input Pin regarding the GPIO setup - can anyone explain this? I don't want to shortcircuit the transceiver/microcontroller when attaching the Microcontroller's CAN RX pin to the transceivers RX Pin - the transceiver must drive the pin while the microcontroller's CAN rx pin must have high impedance (Input).Does the microcontroller internally disable the Push/Pull gates as the CAN is enabled for a Pin or what is the logic in having to configure an Input pin as Alternate Push/Pull in order to get it to work? The microcontroller in question is the STM32F429.Thanks.Lars #stm32f429-can-gpio-configuration2014-09-08 10:14 AM
Well you can certainly configure the pins as inputs until you complete the configuration of the CAN controller, and then push the pins to the AF mux. The AF interface controls the pins IN/OUT HIGH/LOW states.
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
/* CANx Periph clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
/* CAN register init */
CAN_DeInit(CAN1);
/* Connect CAN_RX and CAN_TX */
GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_CAN1);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_CAN1);
/* GPIO CAN_RX and CAN_TX Configuration */
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
2014-09-09 06:30 AM
So the answer is that the CAN RX input pin must be configured to AF_PP (even though Push/Pull gates refer to output pins - guess I had expected an AF_INPUT option).
Thanks for the reply! Lars