AnsweredAssumed Answered

STM32F4 Discovery CAN pin config

Question asked by vojta.m on Dec 4, 2012
Latest reply on Nov 24, 2014 by Clive One
Dear all,
I am looking forward solution of my problem. I have successfully configured CAN driver in loopback mode, but when I want to connect to physical layer (MCP2551 I/C), there is no output on pins.
#define CANx                       CAN1
#define CAN_FILTER_NMR                0
#define CAN_CLK                    RCC_APB1Periph_CAN1
#define CAN_RX_PIN                 GPIO_Pin_0
#define CAN_TX_PIN                 GPIO_Pin_1
#define CAN_GPIO_PORT              GPIOB
#define CAN_GPIO_CLK               RCC_AHB1Periph_GPIOD
#define CAN_AF_PORT                GPIO_AF_CAN1
#define CAN_RX_SOURCE              GPIO_PinSource0
#define CAN_TX_SOURCE              GPIO_PinSource1

/* Enable the CAN controller interface clock  */
     RCC_AHB1PeriphClockCmd(CAN_GPIO_CLK, ENABLE);
     RCC_APB1PeriphClockCmd(CAN_CLK, ENABLE);

     /* CAN pins configuration */
     GPIO_InitTypeDef GPIO_InitStructure;
     GPIO_InitStructure.GPIO_Pin = CAN_RX_PIN | CAN_TX_PIN;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; // Push - pull
     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
     GPIO_Init(CAN_GPIO_PORT, &GPIO_InitStructure);


        /* Initialisation of CAN */
     CAN_InitTypeDef CAN_InitStructure;
     CAN_InitStructure.CAN_TTCM = DISABLE;
     CAN_InitStructure.CAN_ABOM = ENABLE; // Automatic bus off managment
     CAN_InitStructure.CAN_AWUM = DISABLE;
     CAN_InitStructure.CAN_NART = DISABLE;
     CAN_InitStructure.CAN_RFLM = DISABLE;
     CAN_InitStructure.CAN_TXFP = ENABLE;
     CAN_InitStructure.CAN_Prescaler = 10; // 500 kbps for 42 MHz,
     CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
     CAN_InitStructure.CAN_BS1 = CAN_BS1_6tq;
     CAN_InitStructure.CAN_BS2 = CAN_BS2_1tq;
     CAN_InitStructure.CAN_Mode = CAN_Mode_LoopBack;
     CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
     uint8_t status = CAN_Init(CANx, &CAN_InitStructure);

I don't know, where the problem may be. I have tested output with oscilloscope and there is no change on the wires.

And the second question - can I connect RX and TX pin to simulate LoopBack mode? (LoopBack mode works fine, but I want to check output). I'm using USB CDC driver, but I have already disabled it and there is no change.

This is my first experience with CAN bus, but  I'm desperate from it for 2 weeks.