Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

Need to help me about stm32 CAN BUS code in Keil

Status
Not open for further replies.

anoney_potter@hotmail.com

Newbie level 6
Joined
Oct 17, 2010
Messages
12
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,366
I did it and it's work but that code is deep in register I think that code is so difficul for me. I just want to config it like this below code


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
void CAN_setup()
 {
  CAN_InitTypeDef        CAN_InitStructure;
  CAN_FilterInitTypeDef  CAN_FilterInitStructure;
  u8 TransmitMailbox = 0; // Keep number of mail box status
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE);
  /* CAN register init */
  CAN_DeInit();
  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_LoopBack;
    //CAN_InitStructure.CAN_Mode=CAN_Mode_Normal;
    /*
    CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;
    CAN_InitStructure.CAN_BS1=CAN_BS1_8tq;
    CAN_InitStructure.CAN_BS2=CAN_BS2_7tq;
    CAN_InitStructure.CAN_Prescaler=1;
    */
    //CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;
    //CAN_InitStructure.CAN_BS1=CAN_BS1_8tq;
    //CAN_InitStructure.CAN_BS2=CAN_BS2_7tq;
    //CAN_InitStructure.CAN_Prescaler=5;        //72MHz/2=36MHz=PCLK1 / 5 => 7200KHz / (1+8+7) => 450KHz
  
    CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;
    CAN_InitStructure.CAN_BS1=CAN_BS1_10tq;
    CAN_InitStructure.CAN_BS2=CAN_BS2_7tq;
    CAN_InitStructure.CAN_Prescaler=4;          //72MHz/2=36MHz=PCLK1 / 4 => 9000KHz / (1+10+7) => 500KHz
  
    //CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;
    //CAN_InitStructure.CAN_BS1=CAN_BS1_10tq;
    //CAN_InitStructure.CAN_BS2=CAN_BS2_7tq;
    //CAN_InitStructure.CAN_Prescaler=2;        //72MHz/2=36MHz=PCLK1 / 2 => 18000KHz / (1+10+7) => 1000KHz
 
    CAN_Init(&CAN_InitStructure);
    // CAN filter setup 
    CAN_FilterInitStructure.CAN_FilterNumber=1;
    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);
}

 
Last edited by a moderator:

anoney_potter@hotmail.com

Newbie level 6
Joined
Oct 17, 2010
Messages
12
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,366
I change from
CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1=CAN_BS1_8tq;
CAN_InitStructure.CAN_BS2=CAN_BS2_7tq;
CAN_InitStructure.CAN_Prescaler=5; //72MHz/2=36MHz=PCLK1 / 5 => 7200KHz / (1+8+7) => 450KHz

to be

CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1=CAN_BS1_10tq;
CAN_InitStructure.CAN_BS2=CAN_BS2_7tq;
CAN_InitStructure.CAN_Prescaler=2; //72MHz/2=36MHz=PCLK1 / 2 => 18000KHz / (1+10+7) => 1000KHz

but it same I don't know why that make me very confuse
 

Astronom

Newbie level 1
Joined
Mar 24, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Russia
Activity points
1,284
Hello. Help to write the program for STM32F103C8T6 which will send in message CAN an example 410 7 00 00 00 0C to DE 00 00 148mc.
Thanks.
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top