我用的主控是三星的ARM7 (S3C44B0X),我想读取网卡的ID码,可是每次读出来的数据都是错误的,网卡的地址线SA0--SA19,我只用了第四位SA0,SA1,SA2,SA3,其他位中只有SA8,SA9接高电平其他都为低电平。网卡的SA0接我主控的ADDR1。而且网卡是接在主控的BANK3上面的。我用示波器测试网卡的IOR,IOW两个脚也发现了一个225nS的脉宽。其中一开始,网卡的SBHE和网卡的地址线SA0连接的,后来我把SBHE连接到主控的一个IO引脚上面了,不知道这两种接法有什么区别或者有一个是错误的。我主控的主时钟配置为50Mhz。我的代码如下:
#include "44B0X.h"
#include "DEF.h"
#define __BIG_ENDIAN 0 //所有模块都是用小端模式
#define CS8900_OFF 0x02
#define CS8900_BASE 0x06000300
#define CS8900_BUS16_0 ((volatile unsigned short *)0x06000300)
#define CS8900_BUS16_1 ((volatile unsigned short *)0x06000302)
#define CS8900_PPTR ((volatile unsigned short *)0x06000314) //(0x06000300 + (0x0A << 1) )
#define CS8900_PDATA ((volatile unsigned short *)0x06000318) //(0x06000300 + (0x0C << 1) )
#define PP_ChipID 0x0000 /* Chip identifier - must be 0x630E */
#define PP_ChipRev 0x0002 /* Chip revision, model codes */
unsigned short ChipID1 = 0;
unsigned short ChipID2 = 0;
unsigned short Read_1 = 0;
unsigned short Read_2 = 0;
unsigned short Read_3 = 0;
unsigned short Read_4 = 0;
unsigned short C_Read = 0;
unsigned int Read_Reg = 0;
/*************************************************************************
**函数名称: System_Init
**函数功能: 系统初始化
**入口参数: 无
**出口参数: 无
***************************************************************************/
void System_Init(void)
{
rSYSCFG = 0x00; // System Configuration
rNCACHBE0 = 0x00000000; // Non Cacheable Area 0
rNCACHBE1 = 0x00000000; // Non Cacheable Area 1
rSBUSCON = 0x80001B1B; // System Bus Control
rPLLCON = 0x5C081; // PLL Control Fpllo=(m*Fin)/(p*2^s)
rCLKCON = 0x7FF8; // Clock Control
rCLKSLOW = 0x9; // Slow Clock Control
rLOCKTIME = 0xFFF; // PLL Lock Time Counter
}
/****************************************************/
void Port_Init(void)
{
//16bit data bus configuration
// PORT A GROUP
// 9 8 7 6 5 4 3 2 1 0
// A24 A23 A22 A21 A20 A19 A18 A17 A16 A0
// 0 1 1 1 1 1 1 1 1 1
rPCONA = 0x0ff; //A24 不配置为地址线
// PORT B GROUP
// 10 9 8 7 6 5 4 3 2 1 0
// /CS5 /CS4 /CS3 /CS2 /CS1 GPB5 GPB4 /SRAS /SCAS SCLK SCKE
// EXT NIC USB IDE SMC NC NC Sdram Sdram Sdram Sdram
// ? ? ? ? ? Out Out ? ? ? ?
// 1 1 1 1 1 0 0 1 1 1 1
rPCONB = 0x14F; //nGCS3配置给网卡
// rPDATB = 0x7ff&~(1<<10);
// PORT C GROUP, BUSWIDTH=16
// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// NC NC Uart1 Uart1 NC NC NC NC NC NC NC NC out out out int
// ? ? ? ? ? ? ? ? ? ? ? ? * * * * *
// 00 00 11 11 00 00 01 01 00 00 00 00 01 01 01 00
rPDATC = 0xfc0F;
rPCONC = 0x45555554;
rPUPC = 0x7FFF; // PULL UP RESISTOR should be enabled to I/O
// PORT D GROUP
// BIT7 6 5 4 3 2 1 0
// VF OUT VLINE VCLK VD3 VD2 VD1 VD0
// 10 01 10 10 10 10 10 10
// rPDATD = 0xbf;
// rPCOND = 0x5555;
// rPUPD = 0x0;
// These pins must be set only after CPU's internal LCD controller is enable
// PORT E GROUP
// 8 7 6 5 4 3 2 1 0
// CODECLK Out Out Out TOUT1 Out(Beep) RXD0 TXD0 ?
// * * * * * * *
// 01 01 01 01 10 01 10 10 00
rPDATE = 0x1ff;
rPCONE = 0x15569;
rPUPE = 0x6;
// PORT F GROUP
// 8 7 6 5 4 3 2 1 0
// IISCLK IISDI IISDO IISLRCK Out Out Input IICSDA IICSCL
// * * * * * * * * *
// 100 100 100 100 01 01 00 10 10
rPCONF = 0x15555; //GPF8 = DIP4 // PF3:LED4 PF4:LED3 PF2:nWait
rPUPF = 0x1FF;
// PORT G GROUP
// 7 6 5 4 3 2 1 0
// INT7 INT6 INT5 INT4 INT3 INT2 INT1 INT0
// S3 S4 S5 S6 NIC IDE USB
// *
// 11 11 11 11 11 11 11 11
rPCONG = 0x1557;
rPUPG = 0xff; // should be enabled
rSPUCR = 0x4; // D15-D0 pull-up disable
rEXTINT = 0x22222022; //All EINT[7:0] will be falling edge triggered. [30:0]
}
static void IcacheInit(void)//8K --RAM
{
int regSYSCFG = 0;
regSYSCFG = rSYSCFG;
regSYSCFG = 0x0;
rSYSCFG |= regSYSCFG; // System Configuration WE = 1
rNCACHBE0 = 0xC0000000; // Non Cacheable Area 0
rNCACHBE1 = 0x00000000; // Non Cacheable Area 1
}
/*************************************************************************
**函数名称: main
**函数功能:
**入口参数:
**出口参数:
***************************************************************************/
void sys_init(void)
{
rWTCON = 0;//关闭看门狗
IcacheInit();//不是能CACHE
rPLLCON = 0x5C081; // PLL Control Fpllo=(m*Fin)/(p*2^s) 50MHz=0x5C081 20MHz=0x20081
rCLKCON = 0x7FF8; // Clock Control
rCLKSLOW = 0x9; // Slow Clock Control
rLOCKTIME = 0xFFF; // PLL Lock Time Counter
}
static void Delay_ms(unsigned int z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=100;y>0;y--);
}
static void Delay_us(unsigned int dly)
{
while(dly--);
}
int main(void)
{
sys_init(); //系统初始化
Port_Init(); //GPIO口初始化
rBWSCON &= ~(0xF << 12);//nGCS3=nUB/nLB
rBWSCON |= (0xD << 12);//nWAIT,16-bit
rBANKCON3 = (0 << 13) | (3 << 11) | (7 << 8) | (1 << 6) | (0 << 4) | (3 << 2) | 0; //Bank3总线配置
Delay_ms(500); //等待复位10Ms
rPDATF |= (1 << 8); Delay_us(10);//Read_SBHE_H
rPDATF &= ~(1 << 8); Delay_us(10);//Read_SBHE_L
rPDATF &= ~(1 << 8); Delay_us(10);//Read_SBHE_L
rPDATF |= (1 << 8); Delay_us(10);//Read_SBHE_H
rPDATF &= ~(1 << 8); Delay_us(10);//Read_SBHE_L
// C_Read = *CS8900_BUS16_1; Delay_us(10);
// C_Read = *CS8900_BUS16_0; Delay_us(10);
// C_Read = *CS8900_BUS16_0; Delay_us(10);
// C_Read = *CS8900_BUS16_1; Delay_us(10);
// C_Read = *CS8900_BUS16_0; Delay_us(10);
rPDATE &= ~(1 << 6); //红色 报警灯
while(1)
{
*CS8900_PPTR = 0x0000;
Delay_us(10);
ChipID1 = *CS8900_PDATA;
*CS8900_PPTR = 0x0002;
Delay_us(10);
ChipID2 = *CS8900_PDATA;
rPDATE &= ~(1 << 6); //红色 报警灯
}
}
期待你们的帮助。在这里先深表感谢。我在网上也看了好多资料基本上是基于S3C2410的,我也是参照成功例子的方法去写的,就是不行。
|