CH32V203G6U CAN通訊問題

使用can通訊的時候,tx引腳沒有數(shù)據(jù)輸出,空閑的時候也不是高電平,例程使用了端口重映射,這里沒有重映射;



初始化代碼如下:

* @return? none

?*/

void CAN_Mode_Init(u8 tsjw, u8 tbs2, u8 tbs1, u16 brp, u8 mode)

{

? ? GPIO_InitTypeDef? ? ? GPIO_InitSturcture = {0};

? ? CAN_InitTypeDef? ? ? ?CAN_InitSturcture = {0};

? ? CAN_FilterInitTypeDef CAN_FilterInitSturcture = {0};


? ? RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE);

? ? RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);


//? ? GPIO_PinRemapConfig(GPIO_Remap1_CAN1, ENABLE);


? ? GPIO_InitSturcture.GPIO_Pin = GPIO_Pin_12;

? ? GPIO_InitSturcture.GPIO_Mode = GPIO_Mode_Out_PP;

? ? GPIO_InitSturcture.GPIO_Speed = GPIO_Speed_50MHz;

? ? GPIO_Init(GPIOA, &GPIO_InitSturcture);


? ? GPIO_InitSturcture.GPIO_Pin = GPIO_Pin_11;

? ? GPIO_InitSturcture.GPIO_Mode = GPIO_Mode_IPU;

? ? GPIO_Init(GPIOA, &GPIO_InitSturcture);


? ? CAN_InitSturcture.CAN_TTCM = DISABLE;

? ? CAN_InitSturcture.CAN_ABOM = DISABLE;

? ? CAN_InitSturcture.CAN_AWUM = DISABLE;

? ? CAN_InitSturcture.CAN_NART = ENABLE;

? ? CAN_InitSturcture.CAN_RFLM = DISABLE;

? ? CAN_InitSturcture.CAN_TXFP = DISABLE;

? ? CAN_InitSturcture.CAN_Mode = mode;

? ? CAN_InitSturcture.CAN_SJW = tsjw;

? ? CAN_InitSturcture.CAN_BS1 = tbs1;

? ? CAN_InitSturcture.CAN_BS2 = tbs2;

? ? CAN_InitSturcture.CAN_Prescaler = brp;

? ? CAN_Init(CAN1, &CAN_InitSturcture);


? ? CAN_FilterInitSturcture.CAN_FilterNumber = 0;


#if(Frame_Format == Standard_Frame)

? ? /* identifier/mask mode, One 32-bit filter, StdId: 0x317 */

? ? CAN_FilterInitSturcture.CAN_FilterMode = CAN_FilterMode_IdMask;

? ? CAN_FilterInitSturcture.CAN_FilterScale = CAN_FilterScale_32bit;

? ? CAN_FilterInitSturcture.CAN_FilterIdHigh = 0x62E0;

? ? CAN_FilterInitSturcture.CAN_FilterIdLow = 0;

? ? CAN_FilterInitSturcture.CAN_FilterMaskIdHigh = 0;

? ? CAN_FilterInitSturcture.CAN_FilterMaskIdLow = 0;


? ? /* identifier/mask mode, Two 16-bit filters, StdId: 0x317,0x316 */

? ? //CAN_FilterInitSturcture.CAN_FilterMode = CAN_FilterMode_IdMask;

? ? //CAN_FilterInitSturcture.CAN_FilterScale = CAN_FilterScale_16bit;

? ? //CAN_FilterInitSturcture.CAN_FilterIdHigh = 0x62E0;

? ? //CAN_FilterInitSturcture.CAN_FilterIdLow = 0xFFF8;

? ? //CAN_FilterInitSturcture.CAN_FilterMaskIdHigh = 0x62C0;

? ? //CAN_FilterInitSturcture.CAN_FilterMaskIdLow = 0xFFF8;


? ? /* identifier list mode, One 32-bit filter, StdId: 0x317,0x316 */

? ? //CAN_FilterInitSturcture.CAN_FilterMode = CAN_FilterMode_IdList;

? ? //CAN_FilterInitSturcture.CAN_FilterScale = CAN_FilterScale_32bit;

? ? //CAN_FilterInitSturcture.CAN_FilterIdHigh = 0x62E0;

? ? //CAN_FilterInitSturcture.CAN_FilterIdLow = 0;

? ? //CAN_FilterInitSturcture.CAN_FilterMaskIdHigh = 0x62C0;

? ? //CAN_FilterInitSturcture.CAN_FilterMaskIdLow = 0;


? ? /* identifier list mode, Two 16-bit filters, StdId: 0x317,0x316,0x315,0x314 */

? ? //CAN_FilterInitSturcture.CAN_FilterMode = CAN_FilterMode_IdList;

? ? //CAN_FilterInitSturcture.CAN_FilterScale = CAN_FilterScale_16bit;

? ? //CAN_FilterInitSturcture.CAN_FilterIdHigh = 0x62E0;

? ? //CAN_FilterInitSturcture.CAN_FilterIdLow = 0x62C0;

? ? //CAN_FilterInitSturcture.CAN_FilterMaskIdHigh = 0x62A0;

? ? //CAN_FilterInitSturcture.CAN_FilterMaskIdLow = 0x6280;


#elif(Frame_Format == Extended_Frame)

? ? /* identifier/mask mode, One 32-bit filter, ExtId: 0x12124567 */

? ? CAN_FilterInitSturcture.CAN_FilterMode = CAN_FilterMode_IdMask;

? ? CAN_FilterInitSturcture.CAN_FilterScale = CAN_FilterScale_32bit;

? ? CAN_FilterInitSturcture.CAN_FilterIdHigh = 0x9092;

? ? CAN_FilterInitSturcture.CAN_FilterIdLow = 0x2B3C;

? ? CAN_FilterInitSturcture.CAN_FilterMaskIdHigh = 0xFFFF;

? ? CAN_FilterInitSturcture.CAN_FilterMaskIdLow = 0xFFFE;


#endif


? ? CAN_FilterInitSturcture.CAN_FilterFIFOAssignment = CAN_Filter_FIFO0;

? ? CAN_FilterInitSturcture.CAN_FilterActivation = ENABLE;

? ? CAN_FilterInit(&CAN_FilterInitSturcture);

}


主函數(shù)調(diào)用初始化

image.png

發(fā)送測試:

image.png


image.png





image.png

TX 引腳的配置改成GPIO_Mode_AF_PP后TX空閑狀態(tài)是高電平,但是還是沒有數(shù)據(jù),仿真px狀態(tài)是發(fā)送成功了,但是示波器看不到數(shù)據(jù),發(fā)送數(shù)據(jù)也不為0。


函數(shù)第四行

RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE );

改為

RCC_APB2PeriphClockCmd( RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA, ENABLE );

試試


謝謝,是這個問題,已經(jīng)解決


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频