TI中文支持网
TI专业的中文技术问题搜集分享网站

TMS320F28335: 使用SPI读写EEPROM芯片AT25640B,EEPROM芯片一直输出高电平。

Part Number:TMS320F28335

您好,

自制板上使用的dsp为f28335,使用的eeprom为at25650b。现在想利用eeprom存储数据,然后现在测试dsp往eeprom读写数,或者读取AT25640B状态寄存器,AT25640B的SPi输出一直是高电平,且波形很奇怪。我的SPI的配置是这样的。

/*
 * SPI_EEP.c
 *
 *  Created on: 2021年10月16日
 *Author:*/
#include "SPI_EEP.h"
void InitSpiGpio()
{InitSpiaGpio();
}

void InitSpiaGpio()
{EALLOW;GpioCtrlRegs.GPBPUD.bit.GPIO54 = 0;// Enable pull-up on GPIO54 (SPISIMOA)GpioCtrlRegs.GPBPUD.bit.GPIO55 = 0;// Enable pull-up on GPIO55 (SPISOMIA)GpioCtrlRegs.GPBPUD.bit.GPIO56 = 0;// Enable pull-up on GPIO56 (SPICLKA)
//GpioCtrlRegs.GPBPUD.bit.GPIO57 = 0;// Enable pull-up on GPIO57 (SPISTEA)GpioCtrlRegs.GPBQSEL2.bit.GPIO54 = 3; // Asynch input GPIO16 (SPISIMOA)GpioCtrlRegs.GPBQSEL2.bit.GPIO55 = 3; // Asynch input GPIO17 (SPISOMIA)GpioCtrlRegs.GPBQSEL2.bit.GPIO56 = 3; // Asynch input GPIO18 (SPICLKA)GpioCtrlRegs.GPBQSEL2.bit.GPIO57 = 3; // Asynch input GPIO19 (SPISTEA)GpioCtrlRegs.GPBMUX2.bit.GPIO54 = 1; // Configure GPIO54 as SPISIMOAGpioCtrlRegs.GPBMUX2.bit.GPIO55 = 1; // Configure GPIO55 as SPISOMIAGpioCtrlRegs.GPBMUX2.bit.GPIO56 = 1; // Configure GPIO56 as SPICLKA
//GpioCtrlRegs.GPBMUX2.bit.GPIO57 = 1; // Configure GPIO57 as SPISTEA

		GpioCtrlRegs.GPBMUX2.bit.GPIO57=0;
		GpioDataRegs.GPBSET.bit.GPIO57=1;
		GpioCtrlRegs.GPBPUD.bit.GPIO57=0;
		GpioCtrlRegs.GPBDIR.bit.GPIO57=1;EDIS;
}
void SPIA_Init(void)
{
	InitSpiaGpio();
	EALLOW;
	SysCtrlRegs.PCLKCR0.bit.SPIAENCLK = 1;// SPI-A
	EDIS;
	SpiaRegs.SPICCR.bit.SPISWRESET = 0; // Reset SPI
	SpiaRegs.SPICCR.all =0x0007;// 数据不复位,上升沿输出、下降沿输入、保留位0、禁用回还模式、传输位数8位。
	SpiaRegs.SPICTL.all =0x0006;// 使能主机模式,正常相位,使能主机发送,禁止接收,溢出中断,禁止SPI中断,正常模式;

	SpiaRegs.SPIBRR=0x0063;//SPI波特率=375000
//	SpiaRegs.SPICCR.bit.CLKPOLARITY = 0;
//	SpiaRegs.SPICTL.bit.CLK_PHASE=1;
	SpiaRegs.SPICCR.all =0x0087;// Relinquish SPI from Reset
	SpiaRegs.SPIPRI.bit.FREE = 0x0001;// Set so breakpoints don't disturb xmission
	SpiaRegs.SPICCR.bit.SPISWRESET = 1; // Reset SPI
}

//uint8_t SPIA_SendReciveData(uint8_t dat)
//{
//	// Transmit data
//	SpiaRegs.SPITXBUF=dat;
//
//	// Wait until data is received
////	while(SpiaRegs.SPIFFRX.bit.RXFFST !=1);
//	while(SpiaRegs.SPISTS.bit.INT_FLAG !=1);
//	return SpiaRegs.SPIRXBUF;
//}
uint8_t SPIA_SendReciveData(uint8_t dat)
{
	u8 retry=0;
	while(SpiaRegs.SPISTS.bit.BUFFULL_FLAG == 1)//等待发送区空  发送缓冲区空时  SR的bit1 为1  不空的时为0 与后的结果为0,继续等待
	{
	retry++;
	if(retry>200)return 0;
	}
	SpiaRegs.SPITXBUF=(dat|0x8000)<<8 ;  //发送一个byte
	retry=0;
	while(SpiaRegs.SPISTS.bit.INT_FLAG != 1)
	{
	retry++;
	if(retry>200)return 0;
	}
	return ((SpiaRegs.SPIRXBUF)&0x00ff);//返回收到的数据

	}



/*
 * @name:eeprom_read_write_byte
 * @function:读取数据
 * @Author:
 */
u8 stsss=2;
//u8 eeprom_read_write_byte(u8 TxData)
//{
//	SpiaRegs.SPITXBUF=TxData;
//
//	// Wait until data is received
////	while(SpiaRegs.SPIFFRX.bit.RXFFST !=1);
//	while(SpiaRegs.SPISTS.bit.INT_FLAG==0){};
////Delay_US(8);
//	DELAY_US(15);
//	stsss=SpiaRegs.SPISTS.bit.INT_FLAG ;
//	return SpiaRegs.SPIRXBUF;
//}
u16 eeprom_read_write_byte(u16 dat)
{
	u8 retry=0;
	while(SpiaRegs.SPISTS.bit.BUFFULL_FLAG == 1)//等待发送区空  发送缓冲区空时  SR的bit1 为1  不空的时为0 与后的结果为0,继续等待
	{
	retry++;
	if(retry>200)return 0;
	}
	SpiaRegs.SPITXBUF=(dat|0x8000)<<8 ;  //发送一个byte
	retry=0;
	while(SpiaRegs.SPISTS.bit.INT_FLAG != 1)
	{
	retry++;
	if(retry>200)return 0;
	}
	return ((SpiaRegs.SPIRXBUF)&0x00ff);//返回收到的数据
}
/*
 * @name:eeprom_read_sr
 * @function:读取AT25640状态寄存器
 * @Author:
 */
u8 temppp=0;
u8 eeprom_read_sr(void)
{
	u8 dat;
	eeprom_ncs;

	eeprom_read_write_byte(RDSR);
//	DELAY_US(15);
	dat = eeprom_read_write_byte(0x00);
	eeprom_cs;
	temppp=dat;
	return  dat;
}

/*
 * @name:eeprom_write_byte
 * @function:写入一个数据
 * @Author:
 */
u8 ddd=0;
void eeprom_write_byte(u16 addr,u8 Dat)//没有问题
{
	unsigned char Add;
//	ddd=eeprom_read_sr()&RDY;
//	while(eeprom_read_sr()&RDY);//等待就绪信号
//	while(0);//等待就绪信号
	eeprom_ncs;//片选
	eeprom_read_write_byte(WREN);//启用数据写入状态
	eeprom_cs;

	eeprom_ncs;

	if(addr>0x00ff)
		eeprom_read_write_byte((WRITE|0x08));
	else
		eeprom_read_write_byte(WRITE);


	Add = (unsigned char)(addr & 0x00);
	eeprom_read_write_byte(Add);


	eeprom_read_write_byte(Dat);
	eeprom_cs;
}
/*
 * @name:eeprom_read_byte
 * @function:读取一个字节
 * @Author:
 */
u8 eeprom_read_byte(u16 addr)//没有问题
{
	u8 dat,add;
//	while(eeprom_read_sr()&RDY);
//	while(0);//等待就绪信号
	eeprom_ncs;

	if(addr>0x00ff)
		eeprom_read_write_byte((READ | 0x08));
	else
		eeprom_read_write_byte(READ);


	add = (unsigned char)(addr & 0x00);
	eeprom_read_write_byte(add);


	dat=eeprom_read_write_byte(0x00);
	eeprom_cs;
	return dat;
}
/*
 * @name:eeprom_read_write_byte
 * @function:连续写入数据
 * @Author:
 */
void eeprom_write_buf(u16 startAddr,u8 *buf,u16 count)
{
	u16 i;
	while(eeprom_read_sr()&RDY);

	eeprom_ncs;
	eeprom_read_write_byte(WREN);
	eeprom_cs;
	eeprom_ncs;

	eeprom_read_write_byte(WRITE);
	eeprom_read_write_byte(startAddr>>8);
	eeprom_read_write_byte(startAddr);

	for(i=0;i<count;i++)
	{
		eeprom_read_write_byte(*buf++);
	}
	eeprom_cs;
}
/*
 * @name:eeprom_write_nbyte
 * @function:连续写入n字节数据
 * @Author:
 */
void eeprom_write_nbyte(u16 startAddr,u8 *buf,u16 count)
{
	u16 pageTotal=count/64;
	u16 pageResidue=count%64;
	u16 i;
	u16 pageCnt=0;

	for(i=0;i<pageTotal;i++)
	{
		eeprom_write_buf(startAddr+pageCnt,&buf[pageCnt],64);
		pageCnt+=64;
	}
	eeprom_write_buf(startAddr+pageCnt,&buf[pageCnt],pageResidue);
}


/*
 * @name:eeprom_read_buf
 * @function:连续读取数据
 * @Author:
 */
void eeprom_read_buf(u16 startAddr,u8 *buf,u16 count)
{
	unsigned int i;
	while(eeprom_read_sr()&RDY);
	eeprom_ncs;

	eeprom_read_write_byte(READ);

	eeprom_read_write_byte(startAddr>>8);
	eeprom_read_write_byte(startAddr);


	for(i=0;i<count;i++)
	{
		*buf++ = eeprom_read_write_byte(0x00);
	}
	eeprom_cs;
}

Green Deng:

你好,抱歉没有使用SPI读取外部EEPROM的经验,这里有一个F28377的SPI读取EEPROM帖子包含程序,可以参考一下

但是我看你的描述似乎两款芯片通讯都没有建立起来啊,有没有检查过硬件上是否有问题?

另外,建议你直接前往英文E2E论坛,看看那边的TI工程师是否有相关经验可以参考的:e2e.ti.com/…/c2000-microcontrollers-forum

,

Wei Qi:

你好,请问F28377的SPI读取EEPROM帖子包含程序的链接可以发一下吗,我找不到

,

Green Deng:

你好,你是在E2E中文论坛看到的吗?是其他工程师分享的帖子?有印象帖子的标题大概是什么吗?

赞(0)
未经允许不得转载:TI中文支持网 » TMS320F28335: 使用SPI读写EEPROM芯片AT25640B,EEPROM芯片一直输出高电平。
分享到: 更多 (0)