完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
下面是我的代码。delay和串口没有放上去。串口是可以正常通的
[C] 纯文本查看 复制代码 #include "me_dio.h" #define MDIO_IN() {GPIOA->CRH &= ~(15<<16);GPIOA->CRH |= 8<<16;GPIOA->ODR |= 1<<12;}#define MDIO_OUT() {GPIOA->CRH &= ~(15<<16);GPIOA->CRH |= 3<<16;}#define MDIO PAout(12) //SCL#define MDC PAout(11) //SDA #define READ_MDIO PAin(12) //SDA /******************************************************************************** Function Name : Mdio_Init* Description : 1ü½ÅÅäÖÃ* Param : None* Attention : None*******************************************************************************/void Mdio_Init(void){GPIO_InitTypeDef GPIO_InitStructure; /* Configure Mdio pins: PA11 -> MDC and PA12 -> MDIO */GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //íÆíêêä3ö GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure);//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_Init(GPIOA, &GPIO_InitStructure);MDIO = 1;MDC = 0;}/******************************************************************************** Function Name : SMI_Read_One_Byte* Description : ¶áè¡ò»¸ö×Ö½ú* param : None* Return : None* Attention : None*******************************************************************************/u8 SMI_Read_One_Byte(void){ u8 i, receive=0;// MDIO_IN(); for(i = 0; i < 8; i++) { receive<<=1; MDC = 0;//à-μíê±Öó delay_us(1); MDC = 1; //éÏéyÑØ′«êäêy¾Y delay_us(1); if(READ_MDIO) {receive |= 0x01;} //éÏéyÑظßμçƽÆú¼ä¶áè¡êy¾Y //delay_us(1);MDC = 0;// } return receive;}/******************************************************************Function Name : SMI_Read_2Bit* Description : ¶áè¡á½¸öbit* param : None* Return : None* Attention : None******************************************************************/u8 SMI_Read_2Bit(void){ u8 i, receive=0; for(i = 0; i < 2; i++) { receive<<=1; MDC = 0;//à-μíê±Öó delay_us(1); MDC = 1; //éÏéyÑØ′«êäêy¾Y delay_us(1); if(READ_MDIO) {receive |= 0x01;} //éÏéyÑظßμçƽÆú¼ä¶áêy¾YMDC = 0;//»Ö¸′μíμçƽ } return receive;}/******************************************************************Function Name : SMI_Write_One_Byte* Description : D′èëò»¸ö×Ö½ú* param : òaD′èëμÄêy¾Y* Return : None* Attention : None******************************************************************/void SMI_Write_One_Byte(u8 data){ u8 i; for(i = 0; i < 8; i++) { MDC = 0; MDIO = ((data&0x80)>>7); delay_us(1); MDC = 1; delay_us(1); MDC = 0; data<<=1; }} /******************************************************************Function Name : SMI_Write_2Bit* Description : D′èëὸöBit* param : òaD′èëμÄêy¾Y* Return : None* Attention : None******************************************************************/void SMI_Write_2Bit(u8 data){ u8 i; MDIO_OUT(); for(i = 0; i < 2; i++) { MDC = 0; MDIO = (data&0x2)>>1; delay_us(1); MDC = 1; delay_us(1); MDC = 0; data<<=1; }}#define START_OF_FRAME_2bit 0x01#define READ_OP_CODE_2bit 0x02#define WRITE_OP_CODE_2bit 0x01#define SMI_OP_CODE_2bit 0x00#define SMI_TA 0x02/******************************************************************Function Name : SMI_Write_Frame* Description : D′èëò»¸öêy¾YÖ¡* PHYAddress : PHYμÄμØÖ· * RHYReg : PHYμļÄ′æÆ÷μØÖ·* PHYValue : òaD′èë¼Ä′æÆ÷μÄêy¾Y* Attention : None******************************************************************/void SMI_Write_Frame(u16 PHYAddress, u16 PHYReg, u16 PHYValue){ u8 addr; addr = (PHYAddress & 0xFF) <<3 | (PHYReg & 0xFF)>>5; MDIO_OUT(); ////32 bit Preamble SMI_Write_One_Byte(0xFF); SMI_Write_One_Byte(0xFF); SMI_Write_One_Byte(0xFF); SMI_Write_One_Byte(0xFF); SMI_Write_One_Byte(0xFF); SMI_Write_One_Byte(0xFF); SMI_Write_One_Byte(0xFF); SMI_Write_One_Byte(0xFF); SMI_Write_2Bit(START_OF_FRAME_2bit); SMI_Write_2Bit(WRITE_OP_CODE_2bit); SMI_Write_One_Byte(addr);SMI_Write_2Bit(PHYReg & 0x03); SMI_Write_2Bit(SMI_TA);SMI_Write_One_Byte(0xFF);SMI_Write_One_Byte(PHYValue); MDIO_IN();//»Ö¸′¸ß×è}/******************************************************************Function Name : SMI_read_Reg* Description : ¶áè¡êy¾YμÄò»¸ö¼Ä′æÆ÷* PHYAddress : PHYD¾Æ¬μÄμØÖ· * RHYReg : PHYμļÄ′æÆ÷μØÖ·* Attention : None******************************************************************/u16 SMI_Read_Reg(u16 PHYAddress, u16 PHYReg){ u8 addr; u16 data; addr = ((PHYAddress & 0xFF)<<3) | ((PHYReg & 0xFF)>>5); ////32 bit Preamble MDIO_OUT(); SMI_Write_One_Byte(0xFF); SMI_Write_One_Byte(0xFF); SMI_Write_One_Byte(0xFF); SMI_Write_One_Byte(0xFF); SMI_Write_2Bit(START_OF_FRAME_2bit); SMI_Write_2Bit(READ_OP_CODE_2bit); SMI_Write_One_Byte(addr);SMI_Write_2Bit(PHYReg & 0x03); MDIO_IN(); data = SMI_Read_2Bit();//SMI_TA should be Z0 data = SMI_Read_One_Byte(); data = data << 8; data = data | SMI_Read_One_Byte(); return data;}/****************************************************************** Function Name : Get_Reg_Value*Description : »ñè¡ò»¸ö¼Ä′æÆ÷μÄÖμ* port : Ö¸¶¨PHY¶Ë¿úoÅ* PHYAddress : Ö¸¶¨¼Ä′æÆ÷μıêoÅ * Return : ·μ»Ø»ñè¡μ½μÄêy¾Y16λ* Attention : None******************************************************************/u16 Get_Reg_Value(u8 port, u8 reg_num){ u16 reg; reg = SMI_Read_Reg(port, reg_num); return reg;} /******************************************************************Function Name : Print_Reg_Value* Description : ½«»ñè¡μ½μļÄ′æÆ÷Öμ·¢Ëíμ½′®¿ú* Attention : None******************************************************************/void Print_Reg_Value(void){u16 send_data; u8 i,port; for(port = 0; port < 31; port++){ for(i = 0; i < 31; i++){ send_data = Get_Reg_Value(port, 0);USART_SendData(USART2, send_data);delay_ms(10);USART_SendData(USART2, port); delay_ms(10);USART_SendData(USART2, i); delay_ms(10); } }}/******************************************************************Function Name : main* Description : Ö÷oˉêy* Attention : 0******************************************************************/int main(void) {delay_init(); //Ñóê±oˉêy3õê¼»ˉ uart_init(115200); //′®¿ú3õê¼»ˉÎa115200Mdio_Init(); while(1){Print_Reg_Value();}return 0; } |
|
相关推荐
3个回答
|
|
顶一下!账号就是QQ,可以私信
|
|
|
|
用的芯片是F103C8T6,求大神帮忙啊。我只是个新手而已,已经纠结了两个星期了
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
如何使用STM32+nrf24l01架构把有线USB设备无线化?
2568 浏览 7 评论
请问能利用51单片机和nRF24L01模块实现实时语音无线传输吗?
2363 浏览 5 评论
3209 浏览 3 评论
2836 浏览 8 评论
为什么ucosii上移植lwip后系统进入了HardFault_Handler?
2787 浏览 4 评论
请教各位大咖:有没有接收频率32M左右的芯片推荐的?先感谢啦!
664浏览 1评论
903浏览 0评论
1024浏览 0评论
667浏览 0评论
497浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-22 15:02 , Processed in 1.187552 second(s), Total 81, Slave 64 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号