AnsweredAssumed Answered

FRDMk64 Interface with AT45DB161

Question asked by sudhakar p on Jul 27, 2015
Latest reply on Aug 3, 2015 by sudhakar p

Hi,

     i am interfacing AT45DB external data flash into kinetis controller. i used DSPI Example project to write and read data from

External data flash. i am using KDS  3.0 and KSDK 1.2.0. can i use same function for write and read data from flash.? because

for reading also we want to send buffer read command and address of flash at that time which function i want to use? i mean which buffer i want to load receive command  sendBuffer or receiveBuffer ?

i attached my code. is correct?   please give some solution.

 

  

uint8_t receiveBuffer[TRANSFER_SIZE] = {0};

uint8_t sendBuffer[TRANSFER_SIZE] = {0};

int main(void)

{

    uint8_t loopCount = 1;

    uint32_t i;

    uint32_t calculatedBaudRate;

 

    dspi_status_t dspiResult;

    dspi_master_state_t masterState;

    dspi_device_t masterDevice;

    dspi_master_user_config_t masterUserConfig = {

        .isChipSelectContinuous     = false,

        .isSckContinuous            = false,

        .pcsPolarity                = kDspiPcs_ActiveLow,

        .whichCtar                  = kDspiCtar0,

        .whichPcs                   = kDspiPcs0

    };

      hardware_init(); 

    OSA_Init();    

    masterDevice.dataBusConfig.bitsPerFrame = 8;

    masterDevice.dataBusConfig.clkPhase     = kDspiClockPhase_SecondEdge;     //* i changed

    masterDevice.dataBusConfig.clkPolarity  = kDspiClockPolarity_ActiveLow     //* i changed

    masterDevice.dataBusConfig.direction    = kDspiMsbFirst;

 

    // Initialize master driver.

    dspiResult = DSPI_DRV_MasterInit(DSPI_MASTER_INSTANCE,

                                     &masterState,

                                     &masterUserConfig);

    if (dspiResult != kStatus_DSPI_Success)

    {

        PRINTF("\r\nERROR: Can not initialize master driver \n\r");

        return -1;

    }

 

    // Configure baudrate.

    masterDevice.bitsPerSec = TRANSFER_BAUDRATE;

    dspiResult = DSPI_DRV_MasterConfigureBus(DSPI_MASTER_INSTANCE,

                                             &masterDevice,

                                             &calculatedBaudRate);

    if (dspiResult != kStatus_DSPI_Success)

    {

        PRINTF("\r\nERROR: failure in configuration bus\n\r");

        return -1;

    }

    else

    {

        PRINTF("\r\n Transfer at baudrate %lu \r\n", calculatedBaudRate);

    }

 

    while(1)

    {

       

 

      /*******************WRITING 'A' CHARACTER  INTO FLASH LOCATION ZER *************************

     i=0;

      sendBuffer[i++]=0x84;     //FLASH BUFFER1 SELECTION COMMAND

      sendBuffer[i++]=0;

      sendBuffer[i++]=((bkp_byte_in>>8)&(0x03));     //ADDRESS

      sendBuffer[i++]=(bkp_byte_in);

      sendBuffer[i++]='A';          //DATA

      txd_size=i;

 

 

        dspiResult = DSPI_DRV_MasterTransferBlocking(DSPI_MASTER_INSTANCE,

                                                             NULL,

                                                             sendBuffer,

                                                             NULL,

                                                             txd_size,

                                                             MASTER_TRANSFER_TIMEOUT);

 

        if (dspiResult != kStatus_DSPI_Success)

        {

            PRINTF("\r\nERROR: send data error \n\r");

            return -1;

        }

        // Wait until slave is ready to send.

        OSA_TimeDelay(100);      

 

/*******************READING 'A' CHARACTER  FROM FLASH LOCATION ZER *************************

     i=0;

    receiveBuffer[i++]=0xD4;

    receiveBuffer[i++]=0;

    receiveBuffer[i++]=((bkp_byte_out>>8)&(0x03));

    receiveBuffer[i++]=(bkp_byte_out);

    receiveBuffer[i++]=0;

    receiveBuffer[i++]=0;

    txd_size=i;

 

        dspiResult = DSPI_DRV_MasterTransferBlocking(DSPI_MASTER_INSTANCE,

                                                             NULL,

                                                             NULL,

                                                             receiveBuffer,

                                                             txd_size,

                                                             MASTER_TRANSFER_TIMEOUT);

 

        if (dspiResult != kStatus_DSPI_Success)

        {

            PRINTF("\r\nERROR: receive data error \n\r");

            return -1;

        }

 

        // Print out receive buffer.

        PRINTF("\r\n Master receive:");

        for (i = 0; i < TRANSFER_SIZE; i++)

        {

            // Print 16 numbers in a line.

            if ((i & 0x0F) == 0)

            {

                PRINTF("\r\n    ");

            }

            PRINTF(" %02X", receiveBuffer[i]);

        }

 

        PRINTF("\r\n DSPI Master Sends/ Recevies Successfully");

        // Wait for press any key.

        PRINTF("\r\n Press any key to run again\n");

        GETCHAR();

        // Increase loop count to change transmit buffer.

        loopCount++;

    }

}

Outcomes