您好,
我使用
STM32F103 48pin , PA11 PA12為USB(使用HID) , PB8 PB9為CAN,
當USB接上時會找到USB裝置,執行CAN傳送,結果USB會斷掉(電腦的裝置管理員顯示錯誤),
而且產生死機現象(一直中斷USB_LP_CAN_RX0_IRQHandler())
CAN1_Init();
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, DISABLE);
USB_Cable = 1;
USB_Port_Init();
if(KEY1 == 0)
{
USB_Cable_Config(DISABLE);
CAN_Write();
Dly10ms();
USB_Cable_Config(ENABLE);
}
void CAN1_Init(void)
{
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN_RX0_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemp
tionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
CAN_DeInit();
CAN_StructInit(&CAN_InitStructure);
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_3tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_5tq;
CAN_InitStructure.CAN_Prescaler = 4;
CAN_Init(&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=((MAIN_CAN_ID16;
CAN_FilterInitStructure.CAN_FilterIdLow=((MAIN_CAN_ID
一周热门 更多>