2017-04-02 08:07 PM
I've been playing with the hal sd card driver today.
printf(' Product name : %lx%x\r\n', pSD_CID_Info.ProdName1, pSD_CID_Info.ProdName2);
where pSD_CID_Info is of the type HAL_SD_CardCIDTypeDef which is
typedef struct
{ __IO uint8_t ManufacturerID; /*!< Manufacturer ID */ __IO uint16_t OEM_AppliID; /*!< OEM/Application ID */ __IO uint32_t ProdName1; /*!< Product Name part1 */ __IO uint8_t ProdName2; /*!< Product Name part2 */ __IO uint8_t ProdRev; /*!< Product Revision */ __IO uint32_t ProdSN; /*!< Product Serial Number */ __IO uint8_t Reserved1; /*!< Reserved1 */ __IO uint16_t ManufactDate; /*!< Manufacturing Date */ __IO uint8_t CID_CRC; /*!< CID CRC */ __IO uint8_t Reserved2; /*!< Always 1 */}HAL_SD_CardCIDTypeDef;
the output is
Product name : 5355303447
but the 0x5355303447 when converted to ascii should read
Product name : SU04G
how do I get there from here?
Solved! Go to Solution.
2017-04-02 09:32 PM
printf(' Product name : %-5s\r\n', &pSD_CID_Info.ProdName1);
{ // perhaps safer
char string[6] = { 0 };
memcpy(string, &pSD_CID_Info.ProdName1, 5);
printf(' Product name : %s\r\n', string);
}
{
char *p = (char *)&pSD_CID_Info.ProdName1;
printf('%c%c%c%c%c\r\n',p[3],p[2],p[1],p[0],p[4]); // Endians as described in your example
printf('%c%c%c%c%c\r\n',p[0],p[1],p[2],p[3],p[4]);
}
2017-04-02 09:32 PM
printf(' Product name : %-5s\r\n', &pSD_CID_Info.ProdName1);
{ // perhaps safer
char string[6] = { 0 };
memcpy(string, &pSD_CID_Info.ProdName1, 5);
printf(' Product name : %s\r\n', string);
}
{
char *p = (char *)&pSD_CID_Info.ProdName1;
printf('%c%c%c%c%c\r\n',p[3],p[2],p[1],p[0],p[4]); // Endians as described in your example
printf('%c%c%c%c%c\r\n',p[0],p[1],p[2],p[3],p[4]);
}