大家好!
想要向大家请教一下CAN端口重映射这个功能。
目前使用的芯片是STM32F105,两路CAN均使用了端口重映射。
目前使用环回模式调试,CAN1,CAN2均可以收到CAN信号。
但是使用普通模式下,使用CAN卡向其发送信号,接收不到。
向CAN卡发送信号也同样接收不到。
想请问一下,重映射部分是否有配置出错。
主要是CAN2部分,CAN1部分由于板子的收发器有些问题所以还没法进行普通模式的调试。
CAN2部分的话,收发器用的TJA1050,测得芯片RX引脚是3.1V,TX引脚是0V。
希望大家能一起看一下!感激不尽!
配置如下
void CAN1_Mode_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap1_CAN1 , ENABLE);
/* Configure CAN1 RX pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure CAN1 TX pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
CAN_DeInit(CAN1);
CAN_StructInit(&CAN_InitStructure);
CAN_InitStructure.CAN_TTCM=DISABLE; //ʱ¼ä´¥·¢Í¨Ñ¶Ä£Ê½
CAN_InitStructure.CAN_ABOM=DISABLE; //×Ô¶¯ÀëÏß¹ÜÀíģʽ
CAN_InitStructure.CAN_AWUM=DISABLE; //×Ô¶¯»½ÐÑģʽ
CAN_InitStructure.CAN_NART=ENABLE; //·Ç×Ô¶¯ÖØ´«Êäģʽ
CAN_InitStructure.CAN_RFLM=DISABLE; //½ÓÊÕFIFOËø¶¨Ä£Ê½
CAN_InitStructure.CAN_TXFP=DISABLE; //·¢ËÍFIFOÓÅÏȼ¶
CAN_InitStructure.CAN_Mode=CAN_Mode_Normal; //Õý³£Ä£Ê½
CAN_InitStructure.CAN_SJW=CAN_SJW_1tq; //ͬ²½ÌøÔ¾1¸öʱ¼äµ¥Ôª
CAN_InitStructure.CAN_BS1=CAN_BS1_9tq; //ʱ¼ä¶Î1Ϊ8¸öʱ¼äµ¥Ôª
CAN_InitStructure.CAN_BS2=CAN_BS2_8tq; //ʱ¼ä¶Î2Ϊ7¸öʱ¼äµ¥Ôª
CAN_InitStructure.CAN_Prescaler=4; //500Kbps
CAN_Init(CAN1, &CAN_InitStructure);
CAN_FilterInitStructure.CAN_FilterNumber=0; //Ö¸¶¨³õʼ»¯µÄ¹ýÂËÆ÷±àºÅΪ0 £¨0~13£©
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask; //±êʶ·ûÆÁ±Îλģʽ
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit; //1¸ö32λµÄ¹ýÂËÆ÷
CAN_FilterInitStructure.CAN_FilterIdHigh=0x0000; //É趨¹ýÂËÆ÷µÄ±êʶ·û£¨32λΪÆä¸ß¶Î£¬16λΪµÚÒ»¸ö£©·¶Î§ÊÇ0x0000~0xffff
CAN_FilterInitStructure.CAN_FilterIdLow=0x0000; //É趨¹ýÂËÆ÷µÄ±êʶ·û£¨32λΪÆäµÍ¶Î£¬16λΪµÚ¶þ¸ö£©·¶Î§ÊÇ0x0000~0xffff
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0x0000; //É趨¹ýÂËÆ÷ÆÁ±Î±êʶ·û»òÕß¹ýÂ˱êʶ·û
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0x0000; //É趨¹ýÂËÆ÷ÆÁ±Î±êʶ·û»òÕß¹ýÂ˱êʶ·û ¹ýÂ˵ıêʶ·û¶¼Îª0˵Ã÷ËùÓеİü¶¼½ÓÊÕ
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=0; //¹ýÂËÆ÷FIFOÖ¸Ïò¹ýÂËÆ÷0 FIFOÓÐÁ½×éÒ»ÖÖÊǵÚ0×飬һÖÖÊǵÚ1×é¡£
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE; //ʹÄܹýÂËÆ÷
CAN_FilterInit(&CAN_FilterInitStructure);
}
void CAN2_Mode_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_CAN2 , ENABLE);
/* Configure CAN2 RX pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure CAN2 TX pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
CAN_DeInit(CAN2);
CAN_StructInit(&CAN_InitStructure);
CAN_InitStructure.CAN_TTCM=DISABLE; //ʱ¼ä´¥·¢Í¨Ñ¶Ä£Ê½
CAN_InitStructure.CAN_ABOM=DISABLE; //×Ô¶¯ÀëÏß¹ÜÀíģʽ
CAN_InitStructure.CAN_AWUM=DISABLE; //×Ô¶¯»½ÐÑģʽ
CAN_InitStructure.CAN_NART=ENABLE; //·Ç×Ô¶¯ÖØ´«Êäģʽ
CAN_InitStructure.CAN_RFLM=DISABLE; //½ÓÊÕFIFOËø¶¨Ä£Ê½
CAN_InitStructure.CAN_TXFP=DISABLE; //·¢ËÍFIFOÓÅÏȼ¶
CAN_InitStructure.CAN_Mode=CAN_Mode_Normal; //Õý³£Ä£Ê½
CAN_InitStructure.CAN_SJW=CAN_SJW_1tq; //ͬ²½ÌøÔ¾1¸öʱ¼äµ¥Ôª
CAN_InitStructure.CAN_BS1=CAN_BS1_9tq; //ʱ¼ä¶Î1Ϊ8¸öʱ¼äµ¥Ôª
CAN_InitStructure.CAN_BS2=CAN_BS2_8tq; //ʱ¼ä¶Î2Ϊ7¸öʱ¼äµ¥Ôª
CAN_InitStructure.CAN_Prescaler=4; //500Kbps
CAN_Init(CAN2, &CAN_InitStructure);
CAN_FilterInitStructure.CAN_FilterNumber=14; //Ö¸¶¨³õʼ»¯µÄ¹ýÂËÆ÷±àºÅΪ0 £¨0~13£©
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask; //±êʶ·ûÆÁ±Îλģʽ
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit; //1¸ö32λµÄ¹ýÂËÆ÷
CAN_FilterInitStructure.CAN_FilterIdHigh=0x0000; //É趨¹ýÂËÆ÷µÄ±êʶ·û£¨32λΪÆä¸ß¶Î£¬16λΪµÚÒ»¸ö£©·¶Î§ÊÇ0x0000~0xffff
CAN_FilterInitStructure.CAN_FilterIdLow=0x0000; //É趨¹ýÂËÆ÷µÄ±êʶ·û£¨32λΪÆäµÍ¶Î£¬16λΪµÚ¶þ¸ö£©·¶Î§ÊÇ0x0000~0xffff
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0x0000; //É趨¹ýÂËÆ÷ÆÁ±Î±êʶ·û»òÕß¹ýÂ˱êʶ·û
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0x0000; //É趨¹ýÂËÆ÷ÆÁ±Î±êʶ·û»òÕß¹ýÂ˱êʶ·û ¹ýÂ˵ıêʶ·û¶¼Îª0˵Ã÷ËùÓеİü¶¼½ÓÊÕ
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=0; //¹ýÂËÆ÷FIFOÖ¸Ïò¹ýÂËÆ÷0 FIFOÓÐÁ½×éÒ»ÖÖÊǵÚ0×飬һÖÖÊǵÚ1×é¡£
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE; //ʹÄܹýÂËÆ÷
CAN_FilterInit(&CAN_FilterInitStructure);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>