AnsweredAssumed Answered

SDHC data read out and winhex read out is not the same....

Question asked by 亚东 李 on Sep 7, 2015
Latest reply on Sep 14, 2015 by 亚东 李

My English is not very good, most of the following to use Google translate. Also please forgive ...

 

MCU is MK30DN512Z, finished sdhc underlying driver test no problem, test data is written to N sectors, then read out the same data.

Plus the ZNFAT, found not detected by sector 0. So stepping discovered buffer data inside is not the same with the check data. Then print out the 0 sector, find the difference. Open winhex looked, I had written into the data is not right, but the microcontroller to read out what I write into the data - the sector should be no problem for a sector write 0, becomes all 0s, write to other I figure it will ......

 

 

0 WINhex sector data

 

0 sector, SDHC data read out (with% x type printing)

 

If I end at 500 in mcu sector write (rearward other sectors also tried the same results) 17 on winhex should see is the one pair Okay, okay, Figure

I write to 499 decimal sectors 35, winhex should show 0x23

     500 sector write decimal 17, winhex should show 0x11

   0-255 write cycle of 501 sectors

 

 

Serial data print out properly

winhex read out data as follows

Summary found that the display is written 01 02

                 Write 02 Display 01

                 Write 03 Display 03

                 Write 05 Display 0A

                 Write 0A display ........... 05

 

Sector read and write functions as follows

 

 

//SD card read a block

//Enter:u32 sector Take Address

//     u8 *buffer Data storage address(Size is at least 512byte)                   

//return value:0: Success

//       other:Failure                                                                                                                       

u8 SD_ReadSingleBlock(u32 sector, u8 *buffer)

{

        u32 rev[4];

        u16 results;

        u32        j;

  u32        *ptr = (u32*)buffer;

//         if(MySD_Reg.CARDTYPE==ESDHC_CARD_SD) //If an ordinary SD card to the block address into a byte address

//         {

//                 sector = sector<<9;

//         }

        sector = sector + 8192;

       

         while (SDHC->PRSSTAT & SDHC_PRSSTAT_DLA_MASK){};//DATA line is idle wait

         SDHC->BLKATTR &= (~ SDHC_BLKATTR_BLKCNT_MASK); //Clear blocks

         SDHC->BLKATTR |= SDHC_BLKATTR_BLKCNT(1);

         results=SD_SendCommand(ESDHC_CMD17,sector,rev); //Send read a single block command

        if(results!=ESDHC_OK) return ESDHC_ERROR_DATA_TRANSFER; 

        //Start reading a sector------------------------------

    //When reading data, each read 4 bytes

        for (j = (512+3)>>2;j!= 0;j--)

        {

            if (SDHC->IRQSTAT & (    SDHC_IRQSTAT_DEBE_MASK //Data End Bit Error

                                  | SDHC_IRQSTAT_DCE_MASK  //Data CRC Error

                                  | SDHC_IRQSTAT_DTOE_MASK)) //DataTimeout Error

            {

                SDHC->IRQSTAT |= SDHC_IRQSTAT_DEBE_MASK

                              | SDHC_IRQSTAT_DCE_MASK

                              | SDHC_IRQSTAT_DTOE_MASK

                              | SDHC_IRQSTAT_BRR_MASK; //Buffer Read Ready

                return ESDHC_ERROR_DATA_TRANSFER;

            }

                                       

            while (0 == (SDHC->PRSSTAT & SDHC_PRSSTAT_BREN_MASK)){}; // //Wait for data ready    

                                                *ptr=SDHC->DATPORT;         *ptr++;       

        }

        return ESDHC_OK;

}

 

 

//Writes a block to SD card                                 

//Enter:u32 sector Sector address

//     u8 *buffer Data storage address 

//return value:0: Success

//       other   :Failure                                                                                                                         

u8 SD_WriteSingleBlock(u32 sector, const u8 *buffer)

{

        u32 rev[4];

        u16 results;

        u32        j;

  u32        *ptr = (u32*)buffer;

//         if(MySD_Reg.CARDTYPE==ESDHC_CARD_SD) //If an ordinary SD card to the block address into a byte address

//         {

//                 sector = sector<<9;

//         }

        sector = sector + 8192;

         while (SDHC->PRSSTAT & SDHC_PRSSTAT_DLA_MASK){};//DATA line is idle wait

        SDHC->BLKATTR &= (~ SDHC_BLKATTR_BLKCNT_MASK); //Clear blocks

        SDHC->BLKATTR |= SDHC_BLKATTR_BLKCNT(1);       

        results=SD_SendCommand(ESDHC_CMD24,sector,rev);

        if(results!=ESDHC_OK) return ESDHC_ERROR_DATA_TRANSFER; 

        //Begins writing a sector------------------------------               

    //When reading data, each read 4 bytes

        for (j = (512)>>2;j!= 0;j--)

        {                                      

            if (SDHC->IRQSTAT & (    SDHC_IRQSTAT_DEBE_MASK //Data End Bit Error

                                  | SDHC_IRQSTAT_DCE_MASK       //Data CRC Error

                                  | SDHC_IRQSTAT_DTOE_MASK))    //DataTimeout Error                                      

            {

                SDHC->IRQSTAT |= SDHC_IRQSTAT_DEBE_MASK

                              | SDHC_IRQSTAT_DCE_MASK

                              | SDHC_IRQSTAT_DTOE_MASK

                              | SDHC_IRQSTAT_BWR_MASK;      //Buffer Write Ready

                return ESDHC_ERROR_DATA_TRANSFER;

            }                                               

            while (0 == (SDHC->PRSSTAT & SDHC_PRSSTAT_BWEN_MASK)){};     //Wait for data ready

                                                        SDHC->DATPORT=*ptr;         *ptr++;      

        }

        return ESDHC_OK;

}

 

 

 

Regrads!

Thank you very much!!

Outcomes