cprintfxilinxmicroblaze

printf in microblaze for hex to char


I am trying xil_printf() inside a for loop and feeding it to a SendBuffer over uart. How can print the characters instead of integers ? All it is printing is hex number...

uint32_t IRAM;
for(Index=0; Index<tsize; Index++){
  int sb = Index*sizeof(uint32_t);
  IRAM = XIo_In32(RAMADD+sb);
  xil_printf("Data: %08x\n\r",IRAM);
}

This prints hex charaters:

Data: 00004241
Data: 00004443
Data: 00004645
Data: 00004847

I tried :

xil_printf("Data: %08c\n\r",IRAM)

and it prints single characters :

Data: A
Data: C

How can I print the the following (converting hex charaters 4241 to AB, 4443 to CD etc...) ?

Data: AB
Data: CD

Solution

  • You need to print two bytes/characters, so you can specify it explicitly in the format string:

    xil_printf("Data: %c%c\n\r", char1, char2);
    

    But first you need to calculate the bytes to print. For example:

    int char1 = (IRAM >> 8) & 0xff;
    int char2 = IRAM & 0xff;
    

    (possibly switch char1 <-> char2; I am not sure about what order you want to print them in)