TI中文支持网
TI专业的中文技术问题咨询交流网站

AM335X GPMC写数据 数据线电平不对

我在用AM335X的GPMC总线驱动一块芯片,我配置好GPMC后发送数据,用逻辑分析仪抓数据,发现有的数据是对的,有的数据又不对

GPMC的初始化

void GPMC_CS1_init(int chip)
{
	u32 val;
	
	if (gpmc_cs_request(chip, SZ_16M, (unsigned long *)&mem_base) < 0)
	{
		printk(KERN_ERR "Failed request for GPMC mem for init\n");
	}
	printk("Got CS%x, address = %lx\n", chip, mem_base);
	
	val = gpmc_read_reg(GPMC_REVISION);
	printk("GPMC revision %d.%d\n", (val >> 4) & 0x0f, val & 0x0f);
	
	//gpmc_write_reg(GPMC_IRQENABLE, 0);
	//gpmc_write_reg(GPMC_IRQSTATUS, 0);
	val = gpmc_read_reg(GPMC_CONFIG);
	gpmc_write_reg(GPMC_CONFIG, (val & 0xFFFFFFFD));
	
	gpmc_cs_write_reg(chip, GPMC_CS_CONFIG1, STNOR_GPMC_CONFIG1);
	gpmc_cs_write_reg(chip, GPMC_CS_CONFIG2, STNOR_GPMC_CONFIG2);
	gpmc_cs_write_reg(chip, GPMC_CS_CONFIG3, STNOR_GPMC_CONFIG3);
	gpmc_cs_write_reg(chip, GPMC_CS_CONFIG4, STNOR_GPMC_CONFIG4);
	gpmc_cs_write_reg(chip, GPMC_CS_CONFIG5, STNOR_GPMC_CONFIG5);
	gpmc_cs_write_reg(chip, GPMC_CS_CONFIG6, STNOR_GPMC_CONFIG6);
	
	nat9914_base = ioremap(mem_base, SZ_16M); 
	
	if (!nat9914_base)
	{
		printk("Failed to ioremap memory\n");
	}
}

然后是写和读函数

void GPMCWrite(int chip, u32 Address, u8 Data)
{
	//printk("write Data \n");
	writeb((u8)Data,(nat9914_base+Address));
	printk("write 0x%x = 0x%x \n",Address,Data); 
}

u8 GPMCRead(int chip, u32 Address)
{
	u8 tmp = 0;
	//printk("read Data \n");
	tmp = readb((nat9914_base+Address));
	printk("read 0x%x = 0x%x \n",Address,tmp); 

	return (u8)tmp; 
}

因为接线的问题,数据用的是AD0~AD7,而且数据线的高低位接反了,地址用的是A6~A8,所以把读写函数封装了一下

void GPIBWrite(u32 Address, u8 Data)
{
	u8 i, temp = 0x00;

	for(i=0;i<8;i++){temp=((Data>>i)&0x01)|temp;if(i<7)temp=temp<<1;}

	GPMCWrite(NAT9914_CHIP, Address << 1, temp);
}

u8 GPIBRead( u32 Address)
{
	u8 i, data=0x00, temp=0x00;

	data = GPMCRead(NAT9914_CHIP, Address << 1);
	for(i=0;i<8;i++)  
	{  
		temp=((data>>i)&0x01)|temp;  
		if(i<7)  
			temp=temp<<1;  
	}
	
	return temp;
}

这是我config1~6的配置

#define STNOR_GPMC_CONFIG1 0x00000002
#define STNOR_GPMC_CONFIG2 0x001D1D05
#define STNOR_GPMC_CONFIG3 0x00020203
#define STNOR_GPMC_CONFIG4 0x12051205
#define STNOR_GPMC_CONFIG5 0x000F1F1F
#define STNOR_GPMC_CONFIG6 0x04000F80

比如,我发送下面12个数据,地址都是对的,但有几个数据是错误的

GPIBWrite(0xa0, 0x15);
GPIBWrite(0x60, 0x1c);
GPIBWrite(0x40, 0x28); //逻辑分析仪看到的是0x20
GPIBWrite(0x60, 0x97);
GPIBWrite(0x00, 0x30);
GPIBWrite(0x20, 0x88);
GPIBWrite(0x60, 0x9e); //逻辑分析仪看到的是0x9f
GPIBWrite(0x40, 0x0a); //
GPIBWrite(0x60, 0x9f); //逻辑分析仪看到的是0x9e
GPIBWrite(0x40, 0x8c); //逻辑分析仪看到的是0x84
GPIBWrite(0x80, 0x05);
GPIBWrite(0x60, 0x00);

然后我在发送每一个数据前先发送一个0,然后再抓数据,居然没有一个数据有错,如下

GPIBWrite(0xa0, 0x00);
GPIBWrite(0xa0, 0x15);

GPIBWrite(0x60, 0x00);
GPIBWrite(0x60, 0x1c);
GPIBWrite(0x40, 0x00); //0x20
GPIBWrite(0x40, 0x28); //0x20

GPIBWrite(0x60, 0x00);
GPIBWrite(0x60, 0x97);

GPIBWrite(0x00, 0x00);
GPIBWrite(0x00, 0x30);

GPIBWrite(0x20, 0x00);
GPIBWrite(0x20, 0x88);
GPIBWrite(0x60, 0x00);
GPIBWrite(0x60, 0x9e);

GPIBWrite(0x40, 0x00);
GPIBWrite(0x40, 0x0a);

GPIBWrite(0x60, 0x00);
GPIBWrite(0x60, 0x9f);

GPIBWrite(0x40, 0x00);
GPIBWrite(0x40, 0x8c);

GPIBWrite(0x80, 0x00);
GPIBWrite(0x80, 0x05);

GPIBWrite(0x60, 0x00);
GPIBWrite(0x60, 0x00);

有没有人遇到过这种情况,求助!

Jian Zhou:

请问驱动什么芯片,同步工作模式还是异步工作模式?

赞(0)
未经允许不得转载:TI中文支持网 » AM335X GPMC写数据 数据线电平不对
分享到: 更多 (0)