Skip to main content
muhammet
Associate II
May 12, 2014
Question

Can-Bus Error

  • May 12, 2014
  • 26 replies
  • 7260 views
Posted on May 12, 2014 at 19:56

The original post was too long to process during our migration. Please click on the attachment to read the original post.
    This topic has been closed for replies.

    26 replies

    Tesla DeLorean
    Guru
    May 12, 2014
    Posted on May 12, 2014 at 23:19

    Don't leave main(), nothing good will happen.

    Don't enable interrupt routines unless you have handlers for them.

    How have you got the pins wired up?

    Do you have a receiver on the bus to sink the data being transmitted?

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    muhammet
    muhammetAuthor
    Associate II
    May 12, 2014
    Posted on May 13, 2014 at 00:39

    The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6ev&d=%2Fa%2F0X0000000bsb%2F1ffKrn7SuBcMdZAB_Hf2h2WoOM3GLLRRfjmwSfyaYCQ&asPdf=false
    Tesla DeLorean
    Guru
    May 12, 2014
    Posted on May 13, 2014 at 01:22

    You still exit main(), you don't want to do that.

    Try generating constant traffic, I don't have my CAN examples to hand, but perhaps a loop?

    while(1)
    CAN_Transmit(CAN1,&TxMessage); // might need to check busy/ready for new tx

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    muhammet
    muhammetAuthor
    Associate II
    May 13, 2014
    Posted on May 13, 2014 at 12:44

    I don't know how I can set constant traffic. If you want I can add the project to look all file. 

    jpeacock2399
    Associate III
    May 13, 2014
    Posted on May 13, 2014 at 15:35

    CAN will not function unless there are two nodes attached to the bus.  Make sure you have two nodes and that there is a terminator at each end of your twisted-pair cable.  You cannot enable one node and send data, it will fail.  If you only have one node turn on silent loopback for software testing.  You won't see any data on the bus but messages will loop back to the same node.

      Jack Peacock
    mubinicyer
    Associate III
    May 13, 2014
    Posted on May 13, 2014 at 15:40

    First, check the circuit, Are there two transcievers on both side? Are they running, I mean Are they powered correctly? (I was trying to run CAN- receive interrupt and after one day I noticed that one of the transciever's power cable was broken :) )

    In your code you are not activating the clock of CAN1, You activete only CAN2 module twice.

    RCC_AHB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_APB1Periph_CAN2, ENABLE);

    muhammet
    muhammetAuthor
    Associate II
    May 13, 2014
    Posted on May 13, 2014 at 17:42

    I set the my code according to your sayings.

    Jack Peacock, I will don't use loopback. Only I will send data from stm pb9 and pb8 pins to beaglebone black.

    #include ''stm32f4xx.h''

    #include ''config.h''

    #include <stdlib.h>

    CAN_InitTypeDef CAN_InitStructure;

    CAN_FilterInitTypeDef CAN_FilterInitStructure;

    CanTxMsg TxMessage;

    uint16_t CAN1_ID;

    uint8_t CAN1_DATA0,CAN1_DATA1,CAN1_DATA2,CAN1_DATA3,CAN1_DATA4,CAN1_DATA5,CAN1_DATA6,CAN1_DATA7;

    __IO uint8_t Can1Flag;

    int main(void)

    {

    NVIC_InitTypeDef NVIC_InitStructure;

    GPIO_InitTypeDef GPIO_InitStructure;

    /* CAN GPIOs configuration **************************************************/

    /* Enable GPIO clock */

    RCC_AHB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);

    /* Connect CAN pins */

    GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_CAN1);

    GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_CAN1);

    /* Configure CAN RX and TX pins */

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

    GPIO_Init(GPIOD, &GPIO_InitStructure);

    /* CAN configuration ********************************************************/

    /* Enable CAN clock */

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);

    /* CAN register init */

    CAN_DeInit(CAN1);

    CAN_StructInit(&CAN_InitStructure);

    /* 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;

    /* CAN Baudrate = 1MBps (CAN clocked at 30 MHz) */

    CAN_InitStructure.CAN_BS1 = CAN_BS1_6tq;

    CAN_InitStructure.CAN_BS2 = CAN_BS2_8tq;

    CAN_InitStructure.CAN_Prescaler = 2;

    CAN_Init(CAN1, &CAN_InitStructure);

    /* CAN filter init */

    CAN_FilterInitStructure.CAN_FilterNumber = 0;

    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 = 0;

    CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;

    CAN_FilterInit(&CAN_FilterInitStructure);

    /* Enable FIFO 0 message pending Interrupt */

    CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);

    NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX0_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x1;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    // transmit */

    TxMessage.StdId = 0x123;

    TxMessage.ExtId = 0x00;

    TxMessage.RTR = CAN_RTR_DATA;

    TxMessage.IDE = CAN_ID_STD;

    TxMessage.DLC = 8;

    TxMessage.Data[0] = 0x02;

    TxMessage.Data[1] = 0x11;

    TxMessage.Data[2] = 0x11;

    TxMessage.Data[3] = 0x11;

    TxMessage.Data[4] = 0x11;

    TxMessage.Data[5] = 0x11;

    TxMessage.Data[6] = 0x11;

    TxMessage.Data[7] = 0x11;

    while(1)

    CAN_Transmit(CAN1,&TxMessage);

    }
    muhammet
    muhammetAuthor
    Associate II
    May 13, 2014
    Posted on May 13, 2014 at 18:07

    I don't know which defination is true at belows?

    RCC_AHB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

    Tesla DeLorean
    Guru
    May 13, 2014
    Posted on May 13, 2014 at 19:14

    RCC_AHB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);

    AHB1 != APB1
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Tesla DeLorean
    Guru
    May 13, 2014
    Posted on May 13, 2014 at 19:18

    For the F2/F4 I had

    CanTxMsg TxMessage;
    volatile uint32_t i = 0;
    uint8_t TransmitMailbox = 0;
    ..
    TransmitMailbox = CAN_Transmit(CAN1, &TxMessage);
    i = 0;
    while((CAN_TransmitStatus(CAN1, TransmitMailbox) != CANTXOK) && (i != 0xFFFFFF)) // Wait on Transmit
    {
    i++;
    }

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..