我用的
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¿ÚÏà¹ØʱÖÓ
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE); //ʹÄÜGPIOAʱÖÓ
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN,ENABLE);//ʹÄÜCAN1ʱÖÓ
//can1¿ÚÒý½ÅÅäÖÃ
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11|GPIO_Pin_12;//³õʼ»¯
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_NOPULL; //ÉÏÀ
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_0);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource12,GPIO_AF_0);
//CAN1¿ÚµÄÏà¹ØÅäÖÃ
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; // »Ø»·²âÊÔģʽ
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_FilterAc
tivation=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--);
}
}
一周热门 更多>