Can-Bus Error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-12 10:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-12 2:19 PM
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?Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-12 3:39 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-12 4:22 PM
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
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-13 3:44 AM
I don't know how I can set constant traffic. If you want I can add the project to look all file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-13 6:35 AM
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- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-13 6:40 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-13 8:42 AM
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); }- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-13 9:07 AM
I don't know which defination is true at belows?
RCC_AHB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-13 10:14 AM
RCC_AHB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
AHB1 != APB1Up vote any posts that you find helpful, it shows what's working..
