打印

STM32F105 can1能接收无法发送,CAN2收发正常

[复制链接]
7543|10
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
zhujw2002|  楼主 | 2012-10-17 10:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
原来使用的是103VE,目前有客户需要双CAN,故直接在原有的板子上换成105VC的片子来调试,目前CAN1无法发送,接收正常,CAN2收发正常;不知道是哪里出了问题,用原来103VE的程序(使用105VC的芯片)CAN1收发正常。
沙发
zhujw2002|  楼主 | 2012-10-17 10:43 | 只看该作者
这是初始化部分:

void CAN_Configuration(void)
{
  GPIO_InitTypeDef         GPIO_InitStructure;
  CAN_InitTypeDef        CAN_InitStructure;
  CAN_FilterInitTypeDef  CAN_FilterInitStructure;
  //CanTxMsg TxMessage;
  RCC_ClocksTypeDef RCC_ClocksStatus;
  
/* if(ACC_BIT)                        //ACC关时,不打开CAN功能
  {
          return;
  }*/
  
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  
  //Configure CAN pin: TX
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
  
        RCC_GetClocksFreq(&RCC_ClocksStatus);
        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_SJW=CAN_SJW_1tq;
        CAN_InitStructure.CAN_BS1=CAN_BS1_13tq;
        CAN_InitStructure.CAN_BS2=CAN_BS2_2tq;
        CAN_InitStructure.CAN_Prescaler=RCC_ClocksStatus.PCLK1_Frequency/(16*250000);      //波特率计算,16M/(1+8+7)/4=250k
   
  CAN_Init(CAN1, &CAN_InitStructure);
  //CAN 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=0x0000;
  CAN_FilterInitStructure.CAN_FilterMaskIdLow=0x0000;
  CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FIFO0;
  CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
  CAN_FilterInit(&CAN_FilterInitStructure);
  CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
#ifdef DOUBLE_CAN_FUNC
   
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
  
  //Configure CAN pin: TX
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
  
  /* CAN register init */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2, ENABLE);
  
  
  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=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_13tq;
        CAN_InitStructure.CAN_BS2=CAN_BS2_2tq;
        CAN_InitStructure.CAN_Prescaler=RCC_ClocksStatus.PCLK1_Frequency/(16*250000);      //波特率计算,16M/(1+8+7)/4=250k
  CAN_Init(CAN2, &CAN_InitStructure);
  /* CAN filter init */
  CAN_FilterInitStructure.CAN_FilterNumber=14;
  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);
  CAN_ITConfig(CAN2, CAN_IT_FMP0, ENABLE);
#endif
  
}

使用特权

评论回复
板凳
zhujw2002|  楼主 | 2012-10-17 10:43 | 只看该作者
// Enable CAN RX0 interrupt IRQ channel
  NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX0_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 7;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
#ifdef DOUBLE_CAN_FUNC
  NVIC_InitStructure.NVIC_IRQChannel = CAN2_RX0_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 12;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
#endif

使用特权

评论回复
地板
zhujw2002|  楼主 | 2012-10-17 10:44 | 只看该作者
TxMessage.ExtId = 0x18FEF328;                        //心跳
                TxMessage.IDE = CAN_ID_EXT;   
                TxMessage.RTR = CAN_RTR_DATA;
                TxMessage.DLC = 8;
                TransmitMailbox = CAN_Transmit(CAN1, &TxMessage);
                i = 0;
                while((CAN_TransmitStatus(CAN1, TransmitMailbox) != CANTXOK) && (i < 0x1FF))
                 {
                        i++;
                }
                if(i >= 0x1FF)
                         Can_Send_FAIL_Cnt ++;
                else
                {
                        Can_Send_FAIL_Cnt = 0x00;
                       
                }

使用特权

评论回复
5
zhujw2002|  楼主 | 2012-10-17 10:45 | 只看该作者
CAN2的发送
TxMessage.ExtId = 0x18000028;                        //CAN ID
                TxMessage.IDE = CAN_ID_EXT;   
                TxMessage.RTR = CAN_RTR_DATA;
                TxMessage.DLC = 8;
               
                TransmitMailbox = CAN_Transmit(CAN2, &TxMessage);
                i = 0;
                while((CAN_TransmitStatus(CAN2, TransmitMailbox) != CANTXOK) && (i < 0x1FF))
                {
                  i++;
                }

使用特权

评论回复
6
zhujw2002|  楼主 | 2012-10-17 10:46 | 只看该作者
将CAN2部分屏蔽掉之后,CAN1仍能无法发送:L

使用特权

评论回复
7
zhujw2002|  楼主 | 2012-10-17 11:17 | 只看该作者
没问题了,:L摆乌龙了,CAN1由于别的限制条件没发送数据

使用特权

评论回复
8
gtekled| | 2012-10-18 14:30 | 只看该作者
很多时候都应该全面考虑一下

使用特权

评论回复
9
coolkee_wang| | 2013-5-24 22:58 | 只看该作者
关注一下

使用特权

评论回复
10
richlsj| | 2013-10-31 18:46 | 只看该作者
遇到同样的问题,急死我了,感觉是时钟的问题

使用特权

评论回复
11
s20100344| | 2014-10-16 16:41 | 只看该作者
我这也是有问题,can总线的问题,

使用特权

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

本版积分规则

36

主题

75

帖子

0

粉丝