ch32V307VCT6的外部以太网PHY

您好,有没有ch32V307VCT6使用外部以太网PHY的例程?

您好,如果是用外部100M的PHY例程本身是兼容的,仅需要将eth_driver.h中的PHY_MODE改为USE_MAC_MII即可。如果是外部1000M的PHY,可以留个邮箱通过邮箱发您。

image.png


好的,多谢!


还有一个问题,一般外部PHY工作之前都需要初始化吧,为什么我看咱们的以太网驱动都没有这方面的代码,也没有SMI(MDC/MDIO)接口的驱动程序?


您好,程序中通过调用ETH_LibInit()实现对网络的初始化。

image.png

image.png

image.png


还有一个问题,为什么我主函数循环发送UDP帧,一直都发送不出去,这是为啥?但是接收一帧UDP发送一帧可以正常实现


您好,如果是在UDPServer的例程中通过调用WCHNET_SocketUdpSendTo();发送失败后len长度会被清零,因此下次调用时需要重新赋len的值。

image.png

如果是在UDPClient的例程中调用WCHNET_SocketSend();发送需要在创建相应的Socket通过生成的SocketID实现数据发送。发送失败后len长度也会清零,处理方式与WCHNET_SocketUdpSendTo();相同。

image.png

image.png

image.png


另外再调试CAN的时候为什么无法发送和接收数据??我用示波器测试PD0和PD1也没有波形。

我硬件上CAN1的用的是PD0和PD1。初始化代码如下。用的是官方的例程进行修改

/*********************************************************************

 * @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收发器使用,PD0与PD1接CAN收发器后通过逻辑分析仪抓到波形如下:

image.png


我有外接收发器,型号为:TCAN1042


您好,可加我微信将程序发我,我这边测试一下。WeChat:19951759326


您好,我有一个问题,CAN查询接收发送例程中,为什么CAN2的例程都不需要设置ID过滤呢?我看函数里面都是对CAN1的寄存器操作。另外我通过什么来确定,数据是接收到CAN_FIFO0还是CAN_FIFO1呢??


您好,这边有一个CAN1与CAN2共用的例程(采用中断方式接收),您可以参考一下。

icon_rar.gifEVT-CAN1-CAN2中断.zip



只有登录才能回复,可以选择微信账号登录