您好,有沒(méi)有ch32V307VCT6使用外部以太網(wǎng)PHY的例程?
您好,如果是用外部100M的PHY例程本身是兼容的,僅需要將eth_driver.h中的PHY_MODE改為USE_MAC_MII即可。如果是外部1000M的PHY,可以留個(gè)郵箱通過(guò)郵箱發(fā)您。
好的,多謝!
還有一個(gè)問(wèn)題,一般外部PHY工作之前都需要初始化吧,為什么我看咱們的以太網(wǎng)驅(qū)動(dòng)都沒(méi)有這方面的代碼,也沒(méi)有SMI(MDC/MDIO)接口的驅(qū)動(dòng)程序?
您好,程序中通過(guò)調(diào)用ETH_LibInit()實(shí)現(xiàn)對(duì)網(wǎng)絡(luò)的初始化。
還有一個(gè)問(wèn)題,為什么我主函數(shù)循環(huán)發(fā)送UDP幀,一直都發(fā)送不出去,這是為啥?但是接收一幀UDP發(fā)送一幀可以正常實(shí)現(xiàn)
您好,如果是在UDPServer的例程中通過(guò)調(diào)用WCHNET_SocketUdpSendTo();發(fā)送失敗后len長(zhǎng)度會(huì)被清零,因此下次調(diào)用時(shí)需要重新賦len的值。
如果是在UDPClient的例程中調(diào)用WCHNET_SocketSend();發(fā)送需要在創(chuàng)建相應(yīng)的Socket通過(guò)生成的SocketID實(shí)現(xiàn)數(shù)據(jù)發(fā)送。發(fā)送失敗后len長(zhǎng)度也會(huì)清零,處理方式與WCHNET_SocketUdpSendTo();相同。
另外再調(diào)試CAN的時(shí)候?yàn)槭裁礋o(wú)法發(fā)送和接收數(shù)據(jù)??我用示波器測(cè)試PD0和PD1也沒(méi)有波形。
我硬件上CAN1的用的是PD0和PD1。初始化代碼如下。用的是官方的例程進(jìn)行修改
/*********************************************************************
?* @fn? ? ? CAN_Mode_Init
?*
?* @brief? ?Initializes CAN communication test mode.
?*? ? ? ? ? Bps =Fpclk1/((tpb1+1+tbs2+1+1)*brp)
?*
?* @param? ?tsjw - CAN synchronisation jump width.
?*? ? ? ? ? tbs2 - CAN time quantum in bit segment 1.
?*? ? ? ? ? tbs1 - CAN time quantum in bit segment 2.
?*? ? ? ? ? brp - Specifies the length of a time quantum.
?*? ? ? ? ? mode - Test mode.
?*? ? ? ? ? ? CAN_Mode_Normal.
?*? ? ? ? ? ? CAN_Mode_LoopBack.
?*? ? ? ? ? ? CAN_Mode_Silent.
?*? ? ? ? ? ? CAN_Mode_Silent_LoopBack.
?*
?* @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_AFIO | RCC_APB2Periph_GPIOD, ENABLE );
RCC_APB1PeriphClockCmd( RCC_APB1Periph_CAN1, ENABLE );
GPIO_PinRemapConfig( GPIO_Remap2_CAN1, ENABLE);
GPIO_InitSturcture.GPIO_Pin = GPIO_Pin_1;
GPIO_InitSturcture.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitSturcture.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init( GPIOD, &GPIO_InitSturcture);
GPIO_InitSturcture.GPIO_Pin = GPIO_Pin_0;
GPIO_InitSturcture.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init( GPIOD, &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 = 0xFFE0;?
CAN_FilterInitSturcture.CAN_FilterMaskIdLow = 0x0006;?
/* 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 );
}
您好,EVT中CAN例程需要搭配CAN收發(fā)器使用,PD0與PD1接CAN收發(fā)器后通過(guò)邏輯分析儀抓到波形如下:
我有外接收發(fā)器,型號(hào)為:TCAN1042
您好,可加我微信將程序發(fā)我,我這邊測(cè)試一下。WeChat:19951759326
您好,我有一個(gè)問(wèn)題,CAN查詢(xún)接收發(fā)送例程中,為什么CAN2的例程都不需要設(shè)置ID過(guò)濾呢?我看函數(shù)里面都是對(duì)CAN1的寄存器操作。另外我通過(guò)什么來(lái)確定,數(shù)據(jù)是接收到CAN_FIFO0還是CAN_FIFO1呢??