| 1 | int main(void)
 | 
| 2 | {
 | 
| 3 |   SystemInit();
 | 
| 4 | 
 | 
| 5 |   RCC_Configuration();
 | 
| 6 |   RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
 | 
| 7 |   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
 | 
| 8 | 
 | 
| 9 |   GPIO_InitTypeDef GPIO_InitStructure;
 | 
| 10 |   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
 | 
| 11 |   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
 | 
| 12 |   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 | 
| 13 |   GPIO_Init(GPIOA, &GPIO_InitStructure);
 | 
| 14 | 
 | 
| 15 |   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
 | 
| 16 |   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
 | 
| 17 |   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 | 
| 18 |   GPIO_Init(GPIOA, &GPIO_InitStructure);
 | 
| 19 | 
 | 
| 20 |   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
 | 
| 21 |   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
 | 
| 22 |   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 | 
| 23 |   GPIO_Init(GPIOB, &GPIO_InitStructure);
 | 
| 24 | 
 | 
| 25 |   CAN_InitTypeDef CAN_InitStructure;
 | 
| 26 |   CAN_InitStructure.CAN_Prescaler = 26;
 | 
| 27 |   CAN_InitStructure.CAN_BS1 = CAN_BS1_10tq;
 | 
| 28 |   CAN_InitStructure.CAN_BS2 = CAN_BS2_4tq;
 | 
| 29 | 
 | 
| 30 |   CAN_InitStructure.CAN_TTCM = DISABLE;
 | 
| 31 |   CAN_InitStructure.CAN_ABOM = DISABLE;
 | 
| 32 |   CAN_InitStructure.CAN_AWUM = DISABLE;
 | 
| 33 |   CAN_InitStructure.CAN_NART = ENABLE;
 | 
| 34 |   CAN_InitStructure.CAN_RFLM = DISABLE;
 | 
| 35 |   CAN_InitStructure.CAN_TXFP = ENABLE;
 | 
| 36 |   CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
 | 
| 37 |   CAN_InitStructure.CAN_SJW = CAN_SJW_4tq;
 | 
| 38 |   uint8_t temp = CAN_Init(CAN1, &CAN_InitStructure);
 | 
| 39 | 
 | 
| 40 |   CanTxMsg canMessage;
 | 
| 41 | 
 | 
| 42 |   canMessage.StdId = 0x123;
 | 
| 43 |   canMessage.RTR = CAN_RTR_DATA;
 | 
| 44 |   canMessage.IDE = CAN_ID_STD;
 | 
| 45 | 
 | 
| 46 |   canMessage.DLC = 4;
 | 
| 47 | 
 | 
| 48 |   canMessage.Data[0] = 0;
 | 
| 49 |   canMessage.Data[1] = 1;
 | 
| 50 |   canMessage.Data[2] = 2;
 | 
| 51 |   canMessage.Data[3] = 3;
 | 
| 52 | 
 | 
| 53 |     while(1)
 | 
| 54 |     {
 | 
| 55 |       GPIOB->ODR ^= GPIO_Pin_10;  
 | 
| 56 |       CAN_Transmit(CAN1, &canMessage);
 | 
| 57 |       Delay(1700000);
 | 
| 58 |     }
 | 
| 59 | }
 |