AnsweredAssumed Answered

stm32f103c8 spl can, no tx impulse

Question asked by aneox on Feb 11, 2015
Latest reply on Feb 11, 2015 by aneox
Please, help me, i cant start CAN for a week.
I use stm32f103c8 + mcp2551, connected to car can bus. Receiving is working, i got packets in irq. But transmit is always pending. All mail boxes becomes pending. With logic analyser i can see incoming packets on PA11, but PA12 is always in HIGH.
When i switch to loopback mode, i can recieve own message in interrupt, but PA12 is still always HIGH. I thought that car not respond with ack message, but it always should respond to my sending request(if it sended), no respond comming.

init
01.void CAN1_Config(void)
02.{
03.    GPIO_InitTypeDef  GPIO_InitStructure;
04.    NVIC_InitTypeDef NVIC_InitStructure;
05.    CAN_InitTypeDef        CAN_InitStructure;
06.    CAN_FilterInitTypeDef  CAN_FilterInitStructure;
07. 
08.    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
09. 
10.    NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
11.    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
12.    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0;
13.    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
14.    NVIC_Init(&NVIC_InitStructure);
15. 
16. 
17.    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
18.    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE );
19. 
20.    //CAN_RX
21.//    GPIO_InitStructure.GPIO_Pin = GPIO_PinSource8; //PB8
22.//    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
23.//    GPIO_Init(GPIOB, &GPIO_InitStructure);
24.    GPIO_InitStructure.GPIO_Pin = GPIO_PinSource11; //PA11
25.    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
26.    GPIO_Init(GPIOA, &GPIO_InitStructure);
27. 
28.    //CAN_TX
29.//    GPIO_InitStructure.GPIO_Pin = GPIO_PinSource9; //PB9
30.//    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
31.//    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
32.//    GPIO_Init(GPIOB, &GPIO_InitStructure);
33.    GPIO_InitStructure.GPIO_Pin = GPIO_PinSource12; //PA12
34.    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
35.    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
36.    GPIO_Init(GPIOA, &GPIO_InitStructure);
37. 
38.//    GPIO_PinRemapConfig(GPIO_Remap1_CAN1 , ENABLE); //remap to PB8 PB9
39. 
40.    RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
41.    CAN_DeInit(CAN1);
42. 
43.    CAN_InitStructure.CAN_TTCM = DISABLE;
44.    CAN_InitStructure.CAN_ABOM = DISABLE;
45.    CAN_InitStructure.CAN_AWUM = DISABLE;
46.    CAN_InitStructure.CAN_NART = DISABLE;
47.    CAN_InitStructure.CAN_RFLM = DISABLE;
48.    CAN_InitStructure.CAN_TXFP = DISABLE;
49.    CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
50. 
               //500kbit
51.    CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
52.    CAN_InitStructure.CAN_BS1 = CAN_BS1_3tq;
53.    CAN_InitStructure.CAN_BS2 = CAN_BS2_2tq;
54.    CAN_InitStructure.CAN_Prescaler = 12;
55.    CAN_Init(CAN1, &CAN_InitStructure);
56. 
57.    CAN_FilterInitStructure.CAN_FilterNumber = 0;
58.    CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;
59.    CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
60.    CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000;
61.    CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;
62.    CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000;
63.    CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
64.    CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FIFO0;
65.    CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
66.    CAN_FilterInit(&CAN_FilterInitStructure);
67. 
68. 
69.    TxMessage.StdId = 0x321;
70.    TxMessage.RTR = CAN_RTR_DATA;
71.    TxMessage.IDE = CAN_ID_STD;
72.    TxMessage.DLC = 8;
73. 
74.    CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
75.}

sending
01.TxMessage.StdId=PID_REQUEST;
02.TxMessage.RTR = CAN_RTR_DATA;
03.TxMessage.IDE = CAN_ID_STD;
04.TxMessage.DLC = 8;
05.TxMessage.Data[0] = 0x02;
06.TxMessage.Data[1] = 0x01;
07.TxMessage.Data[2] = ENGINE_COOLANT_TEMP;
08.TxMessage.Data[3] = 0x00;
09.TxMessage.Data[4] = 0x00;
10.TxMessage.Data[5] = 0x00;
11.TxMessage.Data[6] = 0x00;
12.TxMessage.Data[7] = 0x00;
13. 
14.do
15.{
16.    transmit_mailbox = CAN_Transmit( CAN1, &TxMessage );
17.}
18.while( transmit_mailbox =! CAN_NO_MB );
19. 
20.txStat1 = CAN_TransmitStatus(CAN1, 0);//0x02 CAN_TxStatus_Pending
21.txStat2 = CAN_TransmitStatus(CAN1, 1);//0x02 CAN_TxStatus_Pending
22.txStat3 = CAN_TransmitStatus(CAN1, 2);//0x02 CAN_TxStatus_Pending
23. 
24.if (txStat1 == CANTXOK || txStat2 == CANTXOK || txStat3 == CANTXOK)
25.    ok = 1; //never

Outcomes