2015-02-10 10:01 PM
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
void
CAN1_Config(
void
)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE );
//CAN_RX
// GPIO_InitStructure.GPIO_Pin = GPIO_PinSource8; //PB8
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
// GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PinSource11;
//PA11
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//CAN_TX
// GPIO_InitStructure.GPIO_Pin = GPIO_PinSource9; //PB9
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
// GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PinSource12;
//PA12
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// GPIO_PinRemapConfig(GPIO_Remap1_CAN1 , ENABLE); //remap to PB8 PB9
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
CAN_DeInit(CAN1);
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;
//500kbit
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_3tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_2tq;
CAN_InitStructure.CAN_Prescaler = 12;
CAN_Init(CAN1, &CAN_InitStructure);
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 = CAN_FIFO0;
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
TxMessage.StdId = 0x321;
TxMessage.RTR = CAN_RTR_DATA;
TxMessage.IDE = CAN_ID_STD;
TxMessage.DLC = 8;
CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
}
sending
TxMessage.StdId=PID_REQUEST;
TxMessage.RTR = CAN_RTR_DATA;
TxMessage.IDE = CAN_ID_STD;
TxMessage.DLC = 8;
TxMessage.Data[0] = 0x02;
TxMessage.Data[1] = 0x01;
TxMessage.Data[2] = ENGINE_COOLANT_TEMP;
TxMessage.Data[3] = 0x00;
TxMessage.Data[4] = 0x00;
TxMessage.Data[5] = 0x00;
TxMessage.Data[6] = 0x00;
TxMessage.Data[7] = 0x00;
do
{
transmit_mailbox = CAN_Transmit( CAN1, &TxMessage );
}
while
( transmit_mailbox =! CAN_NO_MB );
txStat1 = CAN_TransmitStatus(CAN1, 0);
//0x02 CAN_TxStatus_Pending
txStat2 = CAN_TransmitStatus(CAN1, 1);
//0x02 CAN_TxStatus_Pending
txStat3 = CAN_TransmitStatus(CAN1, 2);
//0x02 CAN_TxStatus_Pending
if
(txStat1 == CANTXOK || txStat2 == CANTXOK || txStat3 == CANTXOK)
ok = 1; //never
#stm32f103c8 #stm32f103 #can
2015-02-11 02:16 AM
GPIO_Pin_12
GPIO_PinSource12