2016-03-24 42 views
0

私はフラッシュメモリやSDカードなどにSPIコアからのデータを渡すために、以下のコマンドを使用して読んSPIデータ書き込み/

私たちは与える必要が\節約するために、メモリ上のデータを読むことを理解し
XSpi_Transfer(&Spi, SendData, ResData, 1); 

アドレス。

しかし、わからないことは、上記のコマンドでアドレスを指定する方法です。

答えて

0

このgithub pageは、以下の構文を使用してSpiAtmelFlashRead名前例関数を示す:

SPI_Status = SpiAtmelFlashRead(&spi, Address, ByteCount); 

リード関数内のコードがある:

/*****************************************************************************/ 
/** 
* 
* This function reads data from the Atmel Flash device connected to the SPI 
* interface. 
* 
* @param SpiPtr is a pointer to the SPI driver component to use. 
* @param Addr is the address from which the data is to be read from 
*  the Flash. 
* @param ByteCount is the number of bytes to read. 
* 
* @return XST_SUCCESS if successful else XST_FAILURE. 
* 
* @note  None. 
* 
******************************************************************************/ 
int SpiAtmelFlashRead(XSpi *SpiPtr, u32 Address, u16 ByteCount) 
{ 
    u16 Index; 

    /* 
    * Setup the read command with the specified address and data for the 
    * Atmel Flash. 
    */ 
    WriteBuffer[ATMEL_COMMAND_OFFSET] = ATMEL_COMMAND_READ; 
    WriteBuffer[ATMEL_ADDRESS_BYTE1_OFFSET] = (u8) (Address >> 16); 
    WriteBuffer[ATMEL_ADDRESS_BYTE2_OFFSET] = (u8) (Address >> 8); 
    WriteBuffer[ATMEL_ADDRESS_BYTE3_OFFSET] = (u8) Address; 

    /* 
    * Prepare the write buffer. Fill in some dummy data. 
    */ 
    for(Index = 4; Index < (ByteCount + ATMEL_READ_WRITE_EXTRA_BYTES); 
       Index++) { 
     WriteBuffer[Index] = ATMEL_DUMMYBYTE; 
    } 

    /* 
    * Prepare the Read Buffer. Fill in some initialization data into the 
    * the buffer. 
    */ 
    for(Index = 0; Index < (ByteCount + 
       ATMEL_READ_WRITE_EXTRA_BYTES); Index++) { 
     ReadBuffer[Index] = ATMEL_INITBYTE; 
    } 

    /* 
    * Send the read command to the Atmel Flash to read the specified number 
    * of bytes. 
    */ 
    TransferInProgress = TRUE; 
    XSpi_Transfer(SpiPtr, WriteBuffer, ReadBuffer, 
       ByteCount + ATMEL_READ_WRITE_EXTRA_BYTES); 

    /* 
    * Wait till the Transfer is complete and check if there are any errors 
    * in the transaction. 
    */ 
    while (TransferInProgress); 
    if(ErrorCount != 0) { 
     ErrorCount = 0; 
     return XST_FAILURE; 
    } 

    return XST_SUCCESS; 
} 

このgithub pageSpiAtmelFlashWrite名前例関数を示します次の構文で入力します。

SPI_Status = SpiAtmelFlashWrite(&spi, Address, chunk, ByteCount); 

書き込み関数内のコードがある:

/*****************************************************************************/ 
/** 
* 
* This function writes to the Atmel Flash device connected to the SPI interface. 
* 
* @param SpiPtr is a pointer to the SPI driver component to use. 
* @param Address is the address to which the data is written. 
* @param ByteCount contains the number of bytes to write. 
* 
* @return XST_SUCCESS if successful else XST_FAILURE. 
* 
* @note  None. 
* 
******************************************************************************/ 
int SpiAtmelFlashWrite(XSpi *SpiPtr, u32 Address, u16 ByteCount) 
{ 
    u16 Index; 

    /* 
    * Setup the write command with the specified address, and data to be 
    * written to the flash. 
    */ 
    WriteBuffer[ATMEL_COMMAND_OFFSET]  = ATMEL_COMMAND_WRITE; 
    WriteBuffer[ATMEL_ADDRESS_BYTE1_OFFSET] = (u8) (Address >> 16); 
    WriteBuffer[ATMEL_ADDRESS_BYTE2_OFFSET] = (u8) (Address >> 8); 
    WriteBuffer[ATMEL_ADDRESS_BYTE3_OFFSET] = (u8) (Address); 

    /* 
    * Prepare the write buffer. Fill in the data that is to be written into 
    * the Flash. 
    */ 
    for(Index = 4; Index < (ByteCount + ATMEL_READ_WRITE_EXTRA_BYTES); 
      Index++) { 
     WriteBuffer[Index] = (u8)(ATMEL_TEST_BYTE + Index); 
    } 

    /* 
    * Send the write command, address, and data to the Flash. 
    * No receive buffer is specified since there is nothing to receive. 
    */ 
    TransferInProgress = TRUE; 
    XSpi_Transfer(SpiPtr, WriteBuffer, NULL, 
      ByteCount + ATMEL_READ_WRITE_EXTRA_BYTES) 
          ; 

    /* 
    * Wait till the Transfer is complete and check if there are any errors 
    * in the transaction. 
    */ 
    while (TransferInProgress); 
    if(ErrorCount != 0) { 
     ErrorCount = 0; 
     return XST_FAILURE; 
    } 

    return XST_SUCCESS; 
} 
+0

Atmel Flashの例で説明したように:XSpi_Transfer(SpiPtr、WriteBuffer、NULL、 ByteCount + ATMEL_READ_WRITE_EXTRA_BYTES);私が理解できないのは(上記のXSpi_transfer関数の例で)、WriteBufferに(明らかに)アドレスが含まれていれば、Dataはどの変数に格納されているかです。 –

0

外部記憶装置と通信するための実際のプロトコルは、データシートで指定される(すなわち、アドレスとコマンドをチップに送信する方法は、製造元と製品ラインによって異なります)。あなたの関数が単に単一のSPI転送を開始するように見えます。書き込みコマンド、アドレス、およびデータをまとめて構成するバイト/ワードの特定のシーケンスを送信するには、関数を複数回呼び出す必要があります。繰り返しますが、これはすべてデータシートに依存します。 XSpi_Transferで何が起こっているのかを知ることも役に立ちます。

また、SPIの極性、位相、およびデータビットがSPIコンフィギュレーションルーチンで正しく設定されていることを確認してください。

関連する問題