AnsweredAssumed Answered

STM32F107 CAN using PB5 and PB6

Question asked by lysaght.richard on Dec 4, 2012
Latest reply on Dec 8, 2012 by lysaght.richard
I'm struggling a little bit getting the CAN up and running on my board.  The board is one that we've designed using an STM32F107.  It uses a 25 MHz crystal so the timing should be just like the demo boards.  I'm wondering if I am falling down on the remapping of the CAN functions to PB5 and PB6 (since they are not the first choice for CAN2).

After initialization both CAN RX and CAN TX are high.  When an external source sends out a CAN packet, CAN TX (PB6) starts sending a bunch of data.  But the voltage swing is only about 0.5V when I look at it on the oscilloscope.  I would expect a full scale swing, so I am wondering if my part has been initialize properly.  Here is my CAN INI:

void initialize_CAN()
{
          /**J2284** CAN Baudrate = 500kbps (CAN clocked at 36 MHz APB1 Bus)
          36Mhz / Baudrate = 36,000,000/500,000 = 72 clock cycles
          72 clk = CAN_Prescaler * (1 + CAN_BS1 + CAN_BS2)
          72 / 4 = 18
          18 = (1 + CAN_BS1 + CAN_BS2)
          18 = 1 + 14 + 3
          */

          /**J1939** CAN Baudrate = 250kbps (CAN clocked at 42 MHz APB1 Bus)
          42Mhz / Baudrate = 42,000,000/250,000 = 168 clock cycles
          168 clk = CAN_Prescaler * (1 + CAN_BS1 + CAN_BS2)
          168 / 8 = 21
          21 = (1 + CAN_BS1 + CAN_BS2)
          21 = 1 + 14 + 6
          */
        CAN_InitTypeDef         CAN_InitStructure;
        CAN_FilterInitTypeDef   CAN_FilterInitStructure;
        GPIO_InitTypeDef          GPIO_InitStructure;

        /* GPIO clock enable */
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
        RCC_APB2PeriphClockCmd(GPIO_Remap1_CAN1, ENABLE);
        RCC_APB2PeriphClockCmd(GPIO_Remap_CAN2, ENABLE);

           /* Configure CAN pin: RX */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOB, &GPIO_InitStructure);

        /* Configure CAN pin: TX */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOB, &GPIO_InitStructure);

        GPIO_PinRemapConfig(GPIO_Remap_CAN2, ENABLE);

        /* CANx Periph clock enable */

        RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2, ENABLE);

        /* CAN register init */
        CAN_DeInit(CAN2);

        /* CAN cell init */
        CAN_InitStructure.CAN_TTCM=DISABLE;
        CAN_InitStructure.CAN_ABOM=DISABLE;
        CAN_InitStructure.CAN_AWUM=DISABLE;
        CAN_InitStructure.CAN_NART=DISABLE;
        CAN_InitStructure.CAN_RFLM=DISABLE;
        CAN_InitStructure.CAN_TXFP=DISABLE;
        CAN_InitStructure.CAN_Mode=CAN_Mode_Normal;
        CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;

        /* Baudrate = 250 Kbps */
        CAN_InitStructure.CAN_BS1=CAN_BS1_14tq;
        CAN_InitStructure.CAN_BS2=CAN_BS2_6tq;
        CAN_InitStructure.CAN_Prescaler=8;
        CAN_Init(CAN2, &CAN_InitStructure);

        CAN_FilterInitStructure.CAN_FilterNumber=15;

        CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;
        CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;
        CAN_FilterInitStructure.CAN_FilterIdHigh=0x0000;
        CAN_FilterInitStructure.CAN_FilterIdLow=0x0000;
        CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0x0000;
        CAN_FilterInitStructure.CAN_FilterMaskIdLow=0x0000;
        CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FIFO0;
        CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
        CAN_FilterInit(&CAN_FilterInitStructure);

        /* CAN FIFO0 message pending interrupt enable */
        CAN_ITConfig(CAN2, CAN_IT_FMP0, ENABLE);
}

Any ideas out there?

Much thanks,

Rich


Outcomes