初始化(BOOT1:0 HH(11))
PINSEL2 &= ~(0x00000800); //片选引脚P3.26(1000_0000_0000)
IO3DIR |= 0x04000000;
PINSEL2 &= ~(0x00000008); //复位引脚P1.17(0000_1000)
IO1DIR |= 0x00020000;
BCFG3 = 0x10001460; //RTL8019地址0x83400000,总线读写设置
PINSEL2 &= ~(0x00000020); //16位地址使能
写/读MAC函数:
//head file
#include "config.h"
//define
#define NET_RST 0x00020000
#define NET_BASE_ADDR 0x83400000 //net address
//Write function
void WriteToNet(uint8 ADDR_16,uint16 WRITEDATA)
{
IO3CLR |= 0x04000000;
(*((volatile unsigned short *) NET_BASE_ADDR+ADDR_16))=WRITEDATA; //0x83400000
IO3SET |= 0x04000000;
}
//Read function
uint16 ReadFromNet(uint8 ADDR_16)
{
uint16 temp;
IO3CLR |= 0x04000000;
temp=(*((volatile unsigned short *) NET_BASE_ADDR+ADDR_16)); //0x83400000
IO3SET |= 0x04000000;
return (temp);
}
//change page
void page(uint8 pagenumber)
{
uint8 temp;
temp=ReadFromNet(0); //command register
temp=temp&0x3B ; //注意txp位不能要
pagenumber=pagenumber <<6;
temp=temp | pagenumber;
WriteToNet(0,temp);
}
//set mac
void SetMacID()
{
//把MAC地址写入MY——MAC——ID中
page(1);
WriteToNet(0x01,0x31);
WriteToNet(0x02,0x32);
WriteToNet(0x03,0x33);
WriteToNet(0x04,0x34);
WriteToNet(0x05,0x35);
WriteToNet(0x06,0x36);
page(0);
}
//read mac
void ReadMacID()
{
uint16 address = 0;
Uart0_SendStr((uint8 *)"MAC:");
page(1);
address = ReadFromNet(1);
Uart0_SendByte((uint8)address);
address = ReadFromNet(2);
Uart0_SendByte((uint8)address);
address = ReadFromNet(3);
Uart0_SendByte((uint8)address);
address = ReadFromNet(4);
Uart0_SendByte((uint8)address);
address = ReadFromNet(5);
Uart0_SendByte((uint8)address);
address = ReadFromNet(6);
Uart0_SendByte((uint8)address);
page(0);
}
//net config
void InitNic(uint8 num)
{
uint8 i;
uint8 j;
IO1CLR=NET_RST;
for(i=0;i<200;i++)
{
for(j=0;j<200;j++);
}
IO1SET=NET_RST;
for(i=0;i<200;i++)
{
for(j=0;j<200;j++);
}
IO1CLR=NET_RST;
for(i=0;i<200;i++)
{
for(j=0;j<200;j++);
}
WriteToNet(0x1f,0x00);
for(i=0;i<200;i++)
{
for(j=0;j<200;j++);
}
/**********************************************************************
1.Reg00命令寄存器: CR,命令寄存器,地址偏移量00H,为一个字节
位: 7 6 5 4 3 2 1 0
名字: PS1 PS0 RD2 RD1 RD0 TXP STA STP
//============================================
2.
RD2,RD1,RD0: 这3个位代表要执行的功能。
0 0 1 : 读网卡内存
0 1 0 : 写网卡内存
0 1 1 : 发送网卡数据包
1 * * : 完成或结束DMA的读写操作
//============================================
3.TXP位置1时发送数据包,发完自动清零
//============================================
4.
STA,STP: 这两个位用来启动命令或停止命令
1 0 启动命令
0 1 停止命令
//============================================
********************************************************/
WriteToNet(0x00,0x21); //使芯片处于停止模式,这时进行寄存器设置
for(i=0;i<200;i++)
{
for(j=0;j<200;j++);
}
page(0);
WriteToNet(0x0a,0x00); //清rbcr0
WriteToNet(0x0b,0x00); //清rbcr1
WriteToNet(0x0c, 0xe0); //RCR,监视模式,不接收数据包
WriteToNet(0x0d, 0xe2); //TCR,loop back模式
page(0);
WriteToNet(0x01,0x4c); //PSTART=0X4C
WriteToNet(0x02,0x80); //PSTOP=0X80
WriteToNet(0x03,0x4c); //bnry=0x4c;
page(0);
WriteToNet(0x04,0x40); //TPSR,发送起始页寄存器
WriteToNet(0x07,0xff); //清除所有中断标志位,中断状态寄存器
WriteToNet(0x0f,0x11); //中断屏蔽寄存器清0,禁止中断
WriteToNet(0x0e,0xcb); // 数据配置寄存器,8位dma方式
page(1);
WriteToNet(0x07,0x4d); //curr=0x4d
WriteToNet(0x08,0x00);
WriteToNet(0x09,0x00);
WriteToNet(0x0a,0x00);
WriteToNet(0x0b,0x00);
WriteToNet(0x0c,0x00);
WriteToNet(0x0d,0x00);
WriteToNet(0x0e,0x00);
WriteToNet(0x0f,0x00);
WriteToNet(0x00,0x22); //这时让芯片开始工作
SetMacID(); //将芯片物理地址写入到MAR寄存器
ReadMacID(); //读MAC地址
page(0);
WriteToNet(0x0c,0xcc); //将芯片设置成正常模式,跟外部网络连接
WriteToNet(0x0d,0xe0);
WriteToNet(0x00,0x22); //启动芯片开始工作
WriteToNet(0x07,0xff); //清除所有中断标志位
}
输入MAC:0x31 0x32 0x33 0x34 0x35 0x36
输出MAC:0x7E 0x7E 0x7E 0x7E 0x7E 0x7E
各位大哥,请指教,谢谢
rtl8019的驱动一搜一大堆,不知道楼主出现什么错误了
搞定了,谢谢上面的兄弟了
原因是 我的BOOT1:0 复位时是11
也就是说地址线没有使能,还有其它一大堆的地方没有使能
现将初始化好的参数供上 :
PINSEL2 &= ~(0x00000030);
PINSEL2 |= 0x00000010;
PINSEL2 &= ~(0x00000800); //P3.26
IO3DIR |= 0x04000000; //
PINSEL2 &= ~(0x00000008); //
IO1DIR=IO1DIR|0x00020000; //
BCFG3 = 0x10001460;
PINSEL2 |= 0x00000100; //P3.27
PINSEL2 &= ~(0x0F000000);
PINSEL2 |= 0x0B000000;
谢谢楼上的热心朋友,我在做TCP/IP在LPC2294上的移植,谢谢