//****************************************************************************************
//Chip: SST25VF016B
//Control mode:SPI
//Capacity: 2M x 8bit 0x0000~0x1FFF
//****************************************************************************************
//****************************************************************************************
//提取外扩flash数据,将提取的数据转交给上层
//第一层,上层为Flash_chip_operate.c
//与上层接口函数:EE_RD_data(unsigned int addr,unsigned char *p_data,unsigned char num)
//****************************************************************************************
#include "Flash_chip.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/gpio.h"
#include "driverlib/debug.h"
#include "driverlib/ssi.h"
//****************************************************************************************
#define WREN 0x06 //允许写操作
#define WRDI 0x04 //禁止写操作
#define RDSR 0x05 //读状态寄存器
#define WRSR 0x01 //写状态寄存器
#define READ 0x0B //读数据
#define WRITE 0x02 //写数据
#define EE_SPI_CS_SET GPIOPinWrite(GPIO_PORTA_BASE , GPIO_PIN_3 , 0xFF)
#define EE_SPI_CS_CLR GPIOPinWrite(GPIO_PORTA_BASE , GPIO_PIN_3 , 0x00)
//************************************************************************************
void spi1_init(void)
{
unsigned long temp2[8];
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); //Enable SSIO
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); //Enable GPIOA
//GPIOPinConfigure(GPIO_PE1_SSI1FSS);
GPIOPinConfigure(GPIO_PA2_SSI0CLK); //Configure PA2 as SSI CLK function
GPIOPinConfigure(GPIO_PA4_SSI0RX); //Configure PA4 as SSI RX function
GPIOPinConfigure(GPIO_PA5_SSI0TX); //Configure PA5 as SSI TX function
GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_4 |GPIO_PIN_5); //GPIO_PIN_1 | //Configure Pin() as SSI function
SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0,SSI_MODE_MASTER, 10000000, 8); //Configure the SSI interface
SSIEnable(SSI0_BASE); //Enable the SSI function
GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE , GPIO_PIN_3); //Configyre GPIOA3 as output ,using for control the CE of the external memory
GPIOPadConfigSet(GPIO_PORTA_BASE,GPIO_PIN_3,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD); //Configure GPIOA3 as 推挽,2mA
EE_SPI_CS_SET; //PA3 High level
while(SSIDataGetNonBlocking(SSI0_BASE, &temp2[0])) //get data from the ssi,save at temp2
{
}
}
//************************************************************************************
void Send_Byte(unsigned char data)
{
unsigned long NullData;
SSIDataPut(SSI0_BASE, data);
SSIDataGet(SSI0_BASE, &NullData);
}
//*************************************************************************************
unsigned char Get_Byte(void)
{
unsigned long ReadData;
SSIDataPut(SSI0_BASE, 0xFF); //发送一个无效字节,以产生接收时钟
SSIDataGet(SSI0_BASE, &ReadData);
return (unsigned char)ReadData;
}
void EE_RD_data(unsigned int addr,unsigned char *p_data,unsigned char num)
{
#define SSI_O_SR 0xc
#define SSI_SR_RNE 0x4
#define SSI_O_DR 0x8
#define SSI_SR_TNF 0x02
unsigned char i;//,addr_h,addr_m,addr_l;
register unsigned long ReadAddress=SSI0_BASE+SSI_O_DR;
EE_SPI_CS_CLR;
Send_Byte(READ);
Send_Byte(addr>>16);
Send_Byte(addr>>8);
Send_Byte(addr);
Send_Byte(0xFF); //50M速度时用
__nop();
for(i=0;i<num;i++)
{ //*(p_data+i) = Get_Byte(); //以下三句话相当与这一句话,但是要比这句话快
HWREG(ReadAddress) = 0xff;
while(!(HWREG(SSI0_BASE+SSI_O_SR)&SSI_SR_RNE)){}
*(p_data+i) = (unsigned char )HWREG(ReadAddress);
}
__nop();
EE_SPI_CS_SET;
}
//*************************************************************************************
/*
void EE_RD_data(unsigned int addr,unsigned char *p_data,unsigned char num) //time=time1*5 +time2=76.16us
{
unsigned char i,addr_h,addr_m,addr_l;
EE_SPI_CS_CLR;
addr_l=addr;
addr_m=addr>>8;
addr_h=addr>>16;
Send_Byte(READ); //1M:9.88us ,(time1=9.22+0.3=9.52us) //2M:5.2us
Send_Byte(addr_h);
Send_Byte(addr_m);
Send_Byte(addr_l);
Send_Byte(0xFF); //50M速度时用
__nop();
for(i=0;i<num;i++) //time2=3*9.52=28.56us
{
}
__nop();
EE_SPI_CS_SET;
}
*/
评论0