FRDMk64 Interface with AT45DB161

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FRDMk64 Interface with AT45DB161

1,211 Views
sudhakarp
Contributor V

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++;

    }

}

}
0 Kudos
8 Replies

676 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello,

Hello sud,

"can i use same function for write and read data from flash.? "  - yes.

And have you test your code ? What's the result ? Does it can not work well ?

BR

Alice

0 Kudos

676 Views
sudhakarp
Contributor V

hi,

when i read data flash am not getting 'A'character. i dnt know why..?

that why i asked when reading from data flash which buffer we want to use? receiveBuffer or sendbuffer?. can you check my code?

actually i configured

1)cpol=1, cphase=1

2)master mode

3)and baud rate 500khz

please give some idea.if you have any AT45DB161 flash code send me.

thanks and regards,

sudhakar p

0 Kudos

676 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello sudhakar,

When you reading data from flash , use the receiveBuffer .

And sorry AT45DB161 is not the product of freescale , so i have not code .

I have checked your code , it is hard to fund problem only look at code , please run your project then check the related register:

Check the RXDATA register whether have data  ;

Check the RFDF whether set to 1 ;

If the two register all not work well , please check the signal of flash send whether right .

Hope it helps

Alice

0 Kudos

676 Views
sudhakarp
Contributor V

hi,

i dnt know how to check that register.

i have AT45db161 data flash working code with MCF52235. but in MCF52235 am not used MQX. using register only i did that project. can you give following register name for FRDMk64f120 controller? i gone through document also but am not sure about register. please MAP this register and send me.

this all register am used in MCF52235 so i need FRDM corresponding register, please dnt ignore i need some help

///////////////////////initialization code///////////////////////////////////////////

     MCF_QSPI_QDLYR = 0;

      MCF_QSPI_QIR   = 0;

   

         MCF_QSPI_QMR = (0

        | MCF_QSPI_QMR_MSTR                // Master mode

        | MCF_QSPI_QMR_DOHIE             // QSPI_DOUT high impedance if set

        | MCF_QSPI_QMR_BITS(8)            // Number of bits per trasmission

        | MCF_QSPI_QMR_CPOL              // Clock polarity

        | MCF_QSPI_QMR_CPHA                // Clock phase

        | MCF_QSPI_QMR_BAUD(8));        //  earlier 4 //Baud rate = fsys / (2 * QMR[BAUD])

      MCF_QSPI_QDLYR = (0

        | MCF_QSPI_QDLYR_QCD(0x1E)  //Clock delay from start of CS    0x7F

        | MCF_QSPI_QDLYR_DTL(0x02));        // Delay after transfer      0X7F

    MCF_QSPI_QWR = (0      

        | MCF_QSPI_QWR_CSIV                // QSPI_CS inactive level (active low)

        | MCF_QSPI_QWR_ENDQP(0)            // End of queue pointer     

        | MCF_QSPI_QWR_NEWQP(0));        // Start of queue pointer

    MCF_QSPI_QAR = MCF_QSPI_QAR_CMD;    // Point to command RAM   

    MCF_QSPI_QIR = (0);

////////////////////////////BUSY checking code////////////////

qdlyr = MCF_QSPI_QDLYR;

    if (qdlyr & MCF_QSPI_QDLYR_SPE)    // If QSPI is busy,

   return 1;   // return 1
    else   // Otherwise,
     MCF_QSPI_QIR = MCF_QSPI_QIR_SPIF;
     return 0;  

//////////////////////transmitting data///////////////////////////

MCF_QSPI_QWR = (uint16)(0

        | MCF_QSPI_QWR_CSIV                // QSPI_CS inactive level (active low)

        | MCF_QSPI_QWR_ENDQP(count-1)    // End of queue pointer

        | MCF_QSPI_QWR_NEWQP(0));        // Start of queue pointer

    MCF_QSPI_QAR = MCF_QSPI_QAR_CMD;    // Point to command RAM

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

             MCF_QSPI_QDR =0xFE00;

    MCF_QSPI_QAR = MCF_QSPI_QAR_TRANS;        // Point to tx data RAM

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

    {

        data = block[i];

        MCF_QSPI_QDR = (uint16)MCF_QSPI_QDR_DATA(data);  // Enter data

    }

    MCF_QSPI_QDLYR |= MCF_QSPI_QDLYR_SPE;    // Set QSPI enable bit

////readind data from flash////////////////////////////////////////////////////////////////

for (i=0; i<16; i++)dummy_buff[i]=0;

MCF_QSPI_QAR = MCF_QSPI_QAR_RECV; 

for (i=0; i<16; i++)dummy_buff[i]=MCF_QSPI_QDR;

        

         return(dummy_buff[count-1]);

this code was working 100% in my previous project with MCF52235 but i struggling in FRDMk64. u just see both code and give some solution

0 Kudos

676 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello

Please first check the two register :

(1) When received data ,  we can check this register :

pastedImage_0.png

(2) Check the receive flag :

pastedImage_1.png

\(3) I have not been used the MCF52235 , and there have some different about spi register . please be care check the RM of k64 .

And please also be sue the correct of the hardware configuration . And i will also test the code on my side .

BR

Alice

0 Kudos

676 Views
sudhakarp
Contributor V

hi,

still i have problem.i tried to read status of the AT45DB161 flash. but i am getting 0xFF.

flash read status command :0xD7.

if you got Response  :   0x80 (flash ok).

but am getting 0xFF. so using this command can you make code and send to me. i need how to send data and how to receive data code only. i think its easy for you. once you send 0xD7 command through SPI you will get 0x80 response from AT45DB161. so can you make code for this?  because using your code i will correct my code and also i dnt know how to check SPI data received or not.

thanks and regards,

sudhakar p

0 Kudos

676 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello P,

I have not the AT45DB161 chip, so i only test the demo code you mentioned , that under the KSDK 1.2 ,and it can work well.

And you side  the SPI can received data , so maybe it is the problem of the AT45DB161 chip, please send other command to test , check what it send .

BR

Alice

676 Views
sudhakarp
Contributor V

hi Alice,

     thank you. i got solution. for AT45DB161 we want to give continuous chip-select. in example code  that condition was false after i changed into true. now its working fine. thanks for your support.

thanks and regards,

sudhakar p

0 Kudos