打印

求分析CAN发送在LOOPBACK下可以,NORMAL模式无输出

[复制链接]
5249|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
用STM32F407的CAN1口进行发送,CAN的收发器用SN65HVD230,原理图如下。电脑端用PCI-1680U这个型号的CAN卡接收。

我开始用LOOPBACK模式,中断接收并用串口打印出来,打印的数值和CAN卡接收到的数值一致(这时候CAN卡能收到)
示波器接407的CanTx端看到的图像如下图:


但是问题就是,我把loopback改成normal之后,can卡收不到数据,示波器接407的CanTx端一直是3.3v,附上代码,求大神帮忙分析一下啊~
可以排除的问题:总线电阻测了是60欧。can卡可以算作一个总线上的节点,因为用别的板子可以直接和他收发。
void rt_hw_can_init(void)
{
        NVIC_InitTypeDef                                NVIC_InitStructure;
        GPIO_InitTypeDef                                GPIO_InitStructure;
        CAN_InitTypeDef                                        CAN_InitStructure;
        CAN_FilterInitTypeDef                CAN_FilterInitStructure;

        /* CAN Periph clock enable */
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOF  ,ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);

        GPIO_PinAFConfig (GPIOB,GPIO_PinSource8|GPIO_PinSource9,GPIO_AF_CAN1);
        /* Configure CAN pin: RX & TX*/
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;       
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
        GPIO_Init(GPIOB, &GPIO_InitStructure);   
        /* CAN register init */
        CAN_DeInit(CAN1);
        CAN_StructInit(&CAN_InitStructure);

  /* CAN 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_Mode = CAN_Mode_LoopBack;
        /* CAN Baudrate = 1 MBps (CAN clocked at 32 MHz) */
        CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
        CAN_InitStructure.CAN_BS1 = CAN_BS1_5tq;//CAN_BS1_6tq;
        CAN_InitStructure.CAN_BS2 = CAN_BS2_2tq;//CAN_BS2_5tq;
        CAN_InitStructure.CAN_Prescaler = 4;//3;

        /*Initializes the CAN1 */
        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=0;
        CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
        CAN_ITConfig(CAN1,CAN_IT_FMP0, ENABLE);
        CAN_FilterInit(&CAN_FilterInitStructure);
       
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
        /* Enable CAN1 RX0 interrupt IRQ channel */
        NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX0_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
        /* IT Configuration for CAN1 */  
        CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
       
        rt_kprintf("CAN thread is started!!! Speed is 1MHz!!! \r\n");
}


沙发
hxuetao1989| | 2013-7-11 14:46 | 只看该作者
搭车求指导~~~

使用特权

评论回复
板凳
lisn1234|  楼主 | 2013-7-11 15:32 | 只看该作者
在大神指导下解决了,问题是TX、RX脚不能在一起配置,分开配置就行了,像下面这样
GPIO_PinAFConfig (GPIOB,GPIO_PinSource8,GPIO_AF_CAN1); 
        GPIO_PinAFConfig (GPIOB,GPIO_PinSource9,GPIO_AF_CAN1);
        /* Configure CAN pin: RX */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;//| GPIO_Pin_9;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
        /* Configure CAN pin: TX */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
        GPIO_Init(GPIOB, &GPIO_InitStructure);

使用特权

评论回复
地板
gang544043963| | 2013-11-27 21:46 | 只看该作者
:handshake

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

8

主题

26

帖子

1

粉丝