使用can通讯的时候,tx引脚没有数据输出,空闲的时候也不是高电平,例程使用了端口重映射,这里没有重映射;
初始化代码如下:
* @return none
*/
void CAN_Mode_Init(u8 tsjw, u8 tbs2, u8 tbs1, u16 brp, u8 mode)
{
GPIO_InitTypeDef GPIO_InitSturcture = {0};
CAN_InitTypeDef CAN_InitSturcture = {0};
CAN_FilterInitTypeDef CAN_FilterInitSturcture = {0};
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
// GPIO_PinRemapConfig(GPIO_Remap1_CAN1, ENABLE);
GPIO_InitSturcture.GPIO_Pin = GPIO_Pin_12;
GPIO_InitSturcture.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitSturcture.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitSturcture);
GPIO_InitSturcture.GPIO_Pin = GPIO_Pin_11;
GPIO_InitSturcture.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitSturcture);
CAN_InitSturcture.CAN_TTCM = DISABLE;
CAN_InitSturcture.CAN_ABOM = DISABLE;
CAN_InitSturcture.CAN_AWUM = DISABLE;
CAN_InitSturcture.CAN_NART = ENABLE;
CAN_InitSturcture.CAN_RFLM = DISABLE;
CAN_InitSturcture.CAN_TXFP = DISABLE;
CAN_InitSturcture.CAN_Mode = mode;
CAN_InitSturcture.CAN_SJW = tsjw;
CAN_InitSturcture.CAN_BS1 = tbs1;
CAN_InitSturcture.CAN_BS2 = tbs2;
CAN_InitSturcture.CAN_Prescaler = brp;
CAN_Init(CAN1, &CAN_InitSturcture);
CAN_FilterInitSturcture.CAN_FilterNumber = 0;
#if(Frame_Format == Standard_Frame)
/* identifier/mask mode, One 32-bit filter, StdId: 0x317 */
CAN_FilterInitSturcture.CAN_FilterMode = CAN_FilterMode_IdMask;
CAN_FilterInitSturcture.CAN_FilterScale = CAN_FilterScale_32bit;
CAN_FilterInitSturcture.CAN_FilterIdHigh = 0x62E0;
CAN_FilterInitSturcture.CAN_FilterIdLow = 0;
CAN_FilterInitSturcture.CAN_FilterMaskIdHigh = 0;
CAN_FilterInitSturcture.CAN_FilterMaskIdLow = 0;
/* identifier/mask mode, Two 16-bit filters, StdId: 0x317,0x316 */
//CAN_FilterInitSturcture.CAN_FilterMode = CAN_FilterMode_IdMask;
//CAN_FilterInitSturcture.CAN_FilterScale = CAN_FilterScale_16bit;
//CAN_FilterInitSturcture.CAN_FilterIdHigh = 0x62E0;
//CAN_FilterInitSturcture.CAN_FilterIdLow = 0xFFF8;
//CAN_FilterInitSturcture.CAN_FilterMaskIdHigh = 0x62C0;
//CAN_FilterInitSturcture.CAN_FilterMaskIdLow = 0xFFF8;
/* identifier list mode, One 32-bit filter, StdId: 0x317,0x316 */
//CAN_FilterInitSturcture.CAN_FilterMode = CAN_FilterMode_IdList;
//CAN_FilterInitSturcture.CAN_FilterScale = CAN_FilterScale_32bit;
//CAN_FilterInitSturcture.CAN_FilterIdHigh = 0x62E0;
//CAN_FilterInitSturcture.CAN_FilterIdLow = 0;
//CAN_FilterInitSturcture.CAN_FilterMaskIdHigh = 0x62C0;
//CAN_FilterInitSturcture.CAN_FilterMaskIdLow = 0;
/* identifier list mode, Two 16-bit filters, StdId: 0x317,0x316,0x315,0x314 */
//CAN_FilterInitSturcture.CAN_FilterMode = CAN_FilterMode_IdList;
//CAN_FilterInitSturcture.CAN_FilterScale = CAN_FilterScale_16bit;
//CAN_FilterInitSturcture.CAN_FilterIdHigh = 0x62E0;
//CAN_FilterInitSturcture.CAN_FilterIdLow = 0x62C0;
//CAN_FilterInitSturcture.CAN_FilterMaskIdHigh = 0x62A0;
//CAN_FilterInitSturcture.CAN_FilterMaskIdLow = 0x6280;
#elif(Frame_Format == Extended_Frame)
/* identifier/mask mode, One 32-bit filter, ExtId: 0x12124567 */
CAN_FilterInitSturcture.CAN_FilterMode = CAN_FilterMode_IdMask;
CAN_FilterInitSturcture.CAN_FilterScale = CAN_FilterScale_32bit;
CAN_FilterInitSturcture.CAN_FilterIdHigh = 0x9092;
CAN_FilterInitSturcture.CAN_FilterIdLow = 0x2B3C;
CAN_FilterInitSturcture.CAN_FilterMaskIdHigh = 0xFFFF;
CAN_FilterInitSturcture.CAN_FilterMaskIdLow = 0xFFFE;
#endif
CAN_FilterInitSturcture.CAN_FilterFIFOAssignment = CAN_Filter_FIFO0;
CAN_FilterInitSturcture.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitSturcture);
}
主函数调用初始化
发送测试: