求大神帮帮解答一下
时间:10-02
整理:3721RD
点击:
我用的STM32F072的芯片,在调试CAN程序的时候,用JLINK仿真出来的发送状态永远不是CANTXOK。
CAN的寄存器显示为三个邮箱先后为Pending状态,之后就状态一直为无邮箱可用。芯片无法发出信号。求解啊,各位大神,难道是硬件的原因吗
int main(void)
{
CanTxMsg TxMessage,TxMessage1;
GPIO_InitTypeDef GPIO_InitStructure;
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
//CAN?ú?à1?ê±?ó
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE); //ê1?üGPIOAê±?ó
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN,ENABLE);//ê1?üCAN1ê±?ó
//can1?úòy??????
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11|GPIO_Pin_12;//3?ê??ˉ
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//?′ó?1|?ü
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //?ù?è
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //í?íì?′ó?ê?3?
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //é?à-
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_0);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource12,GPIO_AF_0);
//CAN1?úμ??à1?????
CAN_InitStructure.CAN_TTCM=DISABLE;
CAN_InitStructure.CAN_ABOM=ENABLE;
CAN_InitStructure.CAN_AWUM=DISABLE;
CAN_InitStructure.CAN_NART=DISABLE;
CAN_InitStructure.CAN_RFLM=DISABLE;
CAN_InitStructure.CAN_TXFP=ENABLE;
CAN_InitStructure.CAN_Mode=CAN_Mode_Normal;
CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1=CAN_BS1_10tq;
CAN_InitStructure.CAN_BS2=CAN_BS2_7tq;
CAN_InitStructure.CAN_Prescaler=4;
// CAN_InitStructure.CAN_Mode = CAN_Mode_LoopBack; // ???·2aê??£ê?
CAN_Init(CAN,&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_Filter_FIFO0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
TxMessage.StdId = 0x12;
TxMessage.ExtId = 0x12;
TxMessage.RTR = CAN_RTR_Data; //0x00000000;
TxMessage.IDE = CAN_ID_STD; //0x00000000;
TxMessage.DLC = 8;
TxMessage.Data[0] = 0x01;
TxMessage.Data[1] = 0x00;
TxMessage.Data[2] = 0x00;
TxMessage.Data[3] = 0x00;
TxMessage.Data[4] = 0x00;
TxMessage.Data[5] = 0x00;
TxMessage.Data[6] = 0x00;
TxMessage.Data[7] = 0x00;
while (1)
{
GPIO_WriteBit(GPIOB,GPIO_Pin_9,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_9)));
ii = 0x3fffff;
CAN_Transmit(CAN, &TxMessage);
while(ii--);
}
}
CAN的寄存器显示为三个邮箱先后为Pending状态,之后就状态一直为无邮箱可用。芯片无法发出信号。求解啊,各位大神,难道是硬件的原因吗
int main(void)
{
CanTxMsg TxMessage,TxMessage1;
GPIO_InitTypeDef GPIO_InitStructure;
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
//CAN?ú?à1?ê±?ó
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE); //ê1?üGPIOAê±?ó
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN,ENABLE);//ê1?üCAN1ê±?ó
//can1?úòy??????
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11|GPIO_Pin_12;//3?ê??ˉ
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//?′ó?1|?ü
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //?ù?è
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //í?íì?′ó?ê?3?
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //é?à-
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_0);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource12,GPIO_AF_0);
//CAN1?úμ??à1?????
CAN_InitStructure.CAN_TTCM=DISABLE;
CAN_InitStructure.CAN_ABOM=ENABLE;
CAN_InitStructure.CAN_AWUM=DISABLE;
CAN_InitStructure.CAN_NART=DISABLE;
CAN_InitStructure.CAN_RFLM=DISABLE;
CAN_InitStructure.CAN_TXFP=ENABLE;
CAN_InitStructure.CAN_Mode=CAN_Mode_Normal;
CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1=CAN_BS1_10tq;
CAN_InitStructure.CAN_BS2=CAN_BS2_7tq;
CAN_InitStructure.CAN_Prescaler=4;
// CAN_InitStructure.CAN_Mode = CAN_Mode_LoopBack; // ???·2aê??£ê?
CAN_Init(CAN,&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_Filter_FIFO0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
TxMessage.StdId = 0x12;
TxMessage.ExtId = 0x12;
TxMessage.RTR = CAN_RTR_Data; //0x00000000;
TxMessage.IDE = CAN_ID_STD; //0x00000000;
TxMessage.DLC = 8;
TxMessage.Data[0] = 0x01;
TxMessage.Data[1] = 0x00;
TxMessage.Data[2] = 0x00;
TxMessage.Data[3] = 0x00;
TxMessage.Data[4] = 0x00;
TxMessage.Data[5] = 0x00;
TxMessage.Data[6] = 0x00;
TxMessage.Data[7] = 0x00;
while (1)
{
GPIO_WriteBit(GPIOB,GPIO_Pin_9,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_9)));
ii = 0x3fffff;
CAN_Transmit(CAN, &TxMessage);
while(ii--);
}
}
顶上去,让更多人看到解决一下。