几个星期https://static.assets-stash.eet-china.com/album/old-resources/2008/11/29/cf1a6b99-0e89-44a8-9e87-a4d87c706154.rar之前做过用LM3S6916硬件SPI驱动AT45DB161D的实验,实现了一些简单的功能,后来因为工程中没有再用到AT45DB161D,所以没有再继续做下去。
代码是在网上找的gxlujd(彩虹)写的“ATMEL的DATAFLASH操作函数库(FOR AT45DB161D)”,只要改SPI操作方面的函数就行了。
/* Peripheral definitions for EK-LM3S6965 board */
#define SDC_SSI_BASE SSI0_BASE
#define SDC_SSI_SYSCTL_PERIPH SYSCTL_PERIPH_SSI0
#define SDC_GPIO_PORT_BASE GPIO_PORTA_BASE
#define SDC_GPIO_SYSCTL_PERIPH SYSCTL_PERIPH_GPIOA
#define SDC_SSI_CLK GPIO_PIN_2
#define SDC_SSI_TX GPIO_PIN_5
#define SDC_SSI_RX GPIO_PIN_4
#define SDC_SSI_PINS (SDC_SSI_TX | SDC_SSI_RX | SDC_SSI_CLK)
#define SDC_CS_GPIO_PORT_BASE GPIO_PORTA_BASE
#define SDC_CS_GPIO_SYSCTL_PERIPH SYSCTL_PERIPH_GPIOA
#define SDC_CS GPIO_PIN_6
#define Select_Card() GPIOPinWrite(SDC_CS_GPIO_PORT_BASE, SDC_CS, 0)
#define Deselect_Card() GPIOPinWrite(SDC_CS_GPIO_PORT_BASE, SDC_CS, SDC_CS)
/*--------------------------- spi_hi_speed ----------------------------------*/
#define HI 1
#define LO 0
void spi_hi_speed(unsigned char on)
{
/* Set a SPI clock speed to desired value. */
SSIDisable(SDC_SSI_BASE);
if(on == HI){
/* Max. 20 MBit used for Data Transfer. */
SSIConfig(SDC_SSI_BASE, SSI_FRF_MOTO_MODE_0,SSI_MODE_MASTER,SysCtlClockGet() / 2, 8);
}
else {
/* Max. 400 kBit used in Card Initialization. */
SSIConfig(SDC_SSI_BASE, SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 400000, 8);
}
SSIEnable(SDC_SSI_BASE);
}
/*--------------------------- spi_send --------------------------------------*/
unsigned char spi_send(unsigned char outb)
{
// Write and Read a byte on SPI interface.
unsigned long inb;
SSIDataPut(SDC_SSI_BASE, outb);
SSIDataGet(SDC_SSI_BASE, (unsigned long *)&inb);
return (inb);
}
//*****************************************************************************
//
// SramInit puts the SRAM device in burst mode then polls the status register
// for a valid status response. Returns True if successful.
//
//*****************************************************************************
void SPI_Init(void)
{
/* Initialize and enable the SSP Interface module. */
unsigned long i;
/* Enable the peripherals used to drive the SDC on SSI, and the CS */
SysCtlPeripheralEnable(SDC_SSI_SYSCTL_PERIPH);
SysCtlPeripheralEnable(SDC_GPIO_SYSCTL_PERIPH);
SysCtlPeripheralEnable(SDC_CS_GPIO_SYSCTL_PERIPH);
/* Configure the appropriate pins to be SSI instead of GPIO */
GPIODirModeSet(SDC_GPIO_PORT_BASE, SDC_SSI_PINS, GPIO_DIR_MODE_HW);
GPIODirModeSet(SDC_CS_GPIO_PORT_BASE, SDC_CS, GPIO_DIR_MODE_OUT);
GPIOPadConfigSet(SDC_GPIO_PORT_BASE, SDC_SSI_CLK, GPIO_STRENGTH_4MA,GPIO_PIN_TYPE_STD_WPU);
GPIOPadConfigSet(SDC_GPIO_PORT_BASE, SDC_SSI_TX | SDC_SSI_RX,GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU);
GPIOPadConfigSet(SDC_CS_GPIO_PORT_BASE, SDC_CS,GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU);
/* Deassert the SSI0 chip select */
GPIOPinWrite(SDC_CS_GPIO_PORT_BASE, SDC_CS, SDC_CS);
/* Configure the SSI0 port */
SSIConfig(SDC_SSI_BASE, SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 400000, 8);
SSIEnable(SDC_SSI_BASE);
/* Send SPI Command with card not selected at 400 KBit. */
Deselect_Card();
for (i = 0; i < 16; i++)spi_send(0xFF);
}
其他的没有改动,完整代码在附件中,其中包含有LCDTG12232的驱动,感谢gxlujd(彩虹)无私共享源代码!
用户215995 2009-8-3 23:46