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

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

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

Jump to solution
1,617 Views
斑点大象
Contributor II

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!!

Labels (1)
0 Kudos
Reply
1 Solution
1,355 Views
斑点大象
Contributor II

Really a great shame career ah, the end result is actually reversed D0 and D1. God. Schematic difference had many times Leng Shimo find the problem. Do not say, let me cry while ~~

View solution in original post

0 Kudos
Reply
6 Replies
1,356 Views
斑点大象
Contributor II

Really a great shame career ah, the end result is actually reversed D0 and D1. God. Schematic difference had many times Leng Shimo find the problem. Do not say, let me cry while ~~

0 Kudos
Reply
1,355 Views
斑点大象
Contributor II

。。。。Nothing~~~

0 Kudos
Reply
1,355 Views
bobpaddock
Senior Contributor III

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

That does not look correct to me.

Should it be one of these:

SDHC->DATPORT=*ptr++;  

or

SDHC->DATPORT=*ptr;  ptr++

0 Kudos
Reply
1,355 Views
斑点大象
Contributor II

It does not seem to work, I will continue to look for problems.

Thank you for your help.

0 Kudos
Reply
1,355 Views
斑点大象
Contributor II

Okay, I'll try~~~Thank you ...

0 Kudos
Reply
1,355 Views
斑点大象
Contributor II

help me please~~~~

0 Kudos
Reply