Question
STM32F4 Discovery CAN pin config
Posted on December 04, 2012 at 18:48
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); GPIO_PinAFConfig(CAN_GPIO_PORT, CAN_TX_SOURCE, CAN_AF_PORT); GPIO_PinAFConfig(CAN_GPIO_PORT, CAN_RX_SOURCE, CAN_AF_PORT); /* Initialisation of CAN */ CAN_DeInit(CANx); CAN_InitTypeDef CAN_InitStructure; CAN_StructInit(&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;#ifdef CAN_LOOPBACK CAN_InitStructure.CAN_Mode = CAN_Mode_LoopBack;#else CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;#endif 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.