str710的SPI操作不能写入TXR寄存器:
接线如下:
STR710 AT45DB081 _______ __________ MISO |---------| DO MOSI |---------| DI SCK0 |---------| CK P0.4 |---------| CS P0.5 |---------| RST ______| |__________
我的程序如下:
#define BSPI0_MISO 0x0001 /* SPI0: Master in/Slave out data */ #define BSPI0_MOSI 0x0002 /* SPI0: Master out/Slave In data */ #define BSPI0_SCLK 0x0004 /* SPI0: Serial Clock */ #define BSPI0_SSN 0x0008 /* SPI0: SSN */
#define BSPI1_MISO 0x0010 /* SPI1: Master in/Slave out data */ #define BSPI1_MOSI 0x0020 /* SPI1: Master out/Slave In data */
#define AT45DB_CS BSPI1_MISO //AT45DBXXX片选端 #define AT45DB_RST BSPI1_MOSI //AT45DBXXX复位端
#define M25_SSN 0x0008 /* M25 Ship Select */ #define BSPI1_MC 0x0004 /* BSPI1 Master Config */
#define AT45SelEnable() { GPIO_BitWrite(GPIO0, 4, 0x0); } #define AT45SelDisable() { GPIO_BitWrite(GPIO0, 4, 0x1); } #define AT45RstEnable() { GPIO_BitWrite(GPIO0, 5, 0x0); } #define AT45RstDisable() { GPIO_BitWrite(GPIO0, 5, 0x1); }
/******************************************************************************* * Function Name : InitBSPIFlash * Description : Initialize the BSPIFlash. * Input : None. * Return : None *******************************************************************************/ void InitBSPIFlash (void) { /* Configure GPI00 on mode Alternate function Push Pull */ GPIO_Config ( GPIO0, BSPI0_MISO|BSPI0_SCLK|BSPI0_MOSI, GPIO_AF_PP ); /* Configure SCLK & SSN clock and data lines control */ GPIO_Config ( GPIO0, AT45DB_CS|AT45DB_RST, GPIO_OUT_PP ); /* Initialize BSPI0 device */ BSPI_Init ( BSPI0 ); /* Configure Baud rate Frequency: ---> APB1/6 */ BSPI_ClockDividerConfig (BSPI0, 12); /* Enable BSPI1 */ BSPI_Enable ( BSPI0, ENABLE ); /* Configure BSPI1 as a Master */ BSPI_MasterEnable ( BSPI0, ENABLE ); /* Configure the clock to be active low */ BSPI_ClkActiveHigh ( BSPI0, DISABLE ); /* Enable capturing the first Data sample on the first edge of SCK */ BSPI_ClkFEdge ( BSPI0, DISABLE ); /* Set the word length to 16 bit */ BSPI_8bLEn ( BSPI0, ENABLE ); BSPI_FifoDisable(BSPI0) ; //禁止使用FIFO缓冲 AT45SelDisable() ; // AT45RstEnable() ; //复位AT45DB081 //该处加入延时 AT45RstDisable() ; }
int main (void) { /* Words to be transmitted */
u8 Sendtab[9]={'S','T','R','7','_','B','S','P','I'};
#ifdef DEBUG debug(); #endif InitBSPIFlash() ; //初始化SPI及AT45DB081 AT45SelEnable() ; //AT45DB081片选有效 BSPI_WordSend(BSPI0, 0x57) ; //发读状态寄存器命令 BSPI0->TXR = 0x5700 ; BSPI0->TXR = 0xff00 ; // BSPI_BufferSend(BSPI0,Sendtab,1); BSPI_WordSend(BSPI0, 0xFF) ; Sendtab[0] = BSPI_WordReceive(BSPI0) ; AT45SelDisable() ; // BSPI_BufferReceive(BSPI0,Receivetab,9); while (1) { BSPI_WordSend(BSPI0, 0x57) ; //发读状态寄存器命令 } }
表现: 1、调用的是KEIL的字带函数,控制积存器CSR1,CSR2都可以正确设置,但发送寄存器不能写入,总线上也测不到相应的信号。 2、用ULINK跟踪看出TXR没有被成功写入。 3、汇编代码应该是正确的: 如 BSPI0->TXR = 0x5700 汇编如下
82: BSPI0->TXR = 0x5700 ; 0x400003B8 E3A00C57 MOV R0,#0x00005700 0x400003BC E1C400B4 STRH R0,[R4,#0x04]
R0 = 0x00005700 R4 = 0xc000a000
情况就是这样,不那位仁兄知道,这是怎么回事,还请辞教一二,不胜感激! |