void can_init(void)
{
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* CAN register init */
/* CAN register init */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOA, ENABLE);
/* CAN1 and CAN2 Periph clocks enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
//RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE);
CAN_DeInit(CAN1);
CAN_StructInit(&CAN_InitStructure);
/* Configure CAN1 RX pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure CAN1 TX pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* CAN1 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_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 = 9;
CAN_Init(CAN1, &CAN_InitStructure);
//CAN_Init(CAN2, &CAN_InitStructure);
/* CAN1 filter init */
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 = 0xffff;
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0xffff;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 0;
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
/* Transmit */
}
void can_send_data(void)
{
CanTxMsg TxMessage;
TxMessage.StdId = 0xc12;
TxMessage.ExtId = 0x18fef;
TxMessage.RTR = CAN_RTR_DATA;
TxMessage.IDE = CAN_ID_EXT;
TxMessage.DLC = 8;
TxMessage.Data[0] = send_message[0];
TxMessage.Data[1] = send_message[1];
TxMessage.Data[2] = send_message[2];
TxMessage.Data[3] = send_message[3];
TxMessage.Data[4] = send_message[4];
TxMessage.Data[5] = send_message[5];
TxMessage.Data[6] = send_message[6];
TxMessage.Data[7] = send_message[7];
CAN_Transmit(CAN1, &TxMessage);
}
仿真正常,CAN_TX引脚怎么都没有数据烦死了 请高手指点!!!!!!!!!不胜感激!!!!! |