AnsweredAssumed Answered

STM32F407 CAN Transmit doesn't work

Question asked by yosypenko.vasyl on Dec 15, 2014
Latest reply on Dec 15, 2014 by Clive One
Hello! I use STM32F407 Discovery board and want to use CAN1. My IDE is CoocoxIDE. 
I've put oscilloscope on line PD1 (CAN TX) and haven't seen any  activity...Discovery CAN works without any CAN IC (CAN Driver). Here is my code:

01.const uint8_t TxBuffer[8] = {1,2,3,4,5,6,7,8};
02. 
03.int main(void)
04.{
05.    CAN1_Initialization();
06.    while(1)
07.    {
08. 
09.        CAN1_DataSend(TxBuffer);
10.        _delay_ms(50);
11.    }
12.}
and CAN code:
01.CanTxMsg TxMessage;
02. 
03.void CAN1_Initialization(void)
04.{
05.    GPIO_InitTypeDef            GPIO_InitStructure;
06.    CAN_InitTypeDef             CAN_InitStructure;
07.    CAN_FilterInitTypeDef       CAN_FilterInitStructure;
08.    //NVIC_InitTypeDef          NVIC_InitStructure;
09. 
10.    /* Enable GPIO clock */
11.    RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
12.    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
13. 
14.    /* Configure CAN 1 RX and TX pins */
15.    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
16.    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
17.    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
18.    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
19.    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
20.    GPIO_Init(GPIOD, &GPIO_InitStructure);
21.     
22.    /* Connect CAN 1 pins to AF9 */
23.    GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_CAN1);
24.    GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_CAN1);
25. 
26.    //CAN_DeInit(CAN1);
27. 
28.    /* CAN 1 cell init */
29.    CAN_InitStructure.CAN_Prescaler = 12;
30.    CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
31.    CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
32.    CAN_InitStructure.CAN_BS1 = CAN_BS1_3tq;
33.    CAN_InitStructure.CAN_BS2 = CAN_BS2_3tq;
34.    CAN_InitStructure.CAN_TTCM = DISABLE;
35.    CAN_InitStructure.CAN_ABOM = DISABLE;
36.    CAN_InitStructure.CAN_AWUM = DISABLE;
37.    CAN_InitStructure.CAN_NART = DISABLE;
38.    CAN_InitStructure.CAN_RFLM = DISABLE;
39.    CAN_InitStructure.CAN_TXFP = DISABLE;
40.    CAN_Init( CAN1, &CAN_InitStructure );
41. 
42.    /* CAN1 filter init, accept every message */
43.    CAN_FilterInitStructure.CAN_FilterNumber = 0;  // 0..13 for CAN1, 14..27 for CAN2
44.    CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;
45.    CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
46.    CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000;
47.    CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;
48.    CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000 ;
49.    CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
50.    CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 0;
51.    CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
52.    CAN_FilterInit(&CAN_FilterInitStructure);
53. 
54.    /* Message Init */
55.    TxMessage.StdId = 0x123;
56.    TxMessage.ExtId = 0;
57.    TxMessage.RTR = CAN_RTR_DATA;
58.    TxMessage.IDE = CAN_ID_STD;
59.    TxMessage.DLC = 1;
60. 
61.    TxMessage.Data[0] = 5;
62.}
63. 
64.void CAN1_DataSend(const uint8_t* txBuff )
65.{
66.    TxMessage.StdId = 0x123;
67.    TxMessage.ExtId = 0;
68.    //TxMessage.RTR = CAN_RTR_DATA;
69.    //TxMessage.IDE = CAN_ID_STD;
70.    //TxMessage.DLC = 1;
71. 
72.    TxMessage.Data[0] = 0;
73.    TxMessage.Data[1] = 1;
74.    TxMessage.Data[2] = 2;
75.    TxMessage.Data[3] = 3;
76.    TxMessage.Data[4] = 4;
77.    TxMessage.Data[5] = 5;
78.    TxMessage.Data[6] = 6;
79.    TxMessage.Data[7] = 7;
80. 
81.    /*
82.    for (uint8_t i = 0; i < 8; i++)
83.    {
84.        TxMessage.Data[i] = txBuff[i];
85.    }
86.*/
87.    CAN_Transmit(CAN1, &TxMessage);
88.}
How come I can send data through CAN1?

Outcomes