Displaying binary over AVR UART

avr

I am trying to interface an ENC28J60 ethernet controller IC with an ATmega16 µC. In order to debug my my code, I have built an UART circuit and wrote the appropriate code and I can display any string or character through it on my PC.

But I'm not able to display the register contents of ENC28J60 through UART since the contents are in binary format. I Googled a lot but did not find a way to display binary data through UART. Any help,guidance or comments is welcome.

My SPI code to access the ENC28J60 registers.

uint8_t ENC_readControlRegister()
{
 //pull PC5(chip select) pin low.
 PORTC = (0<<5);
 //put the command corresponding to ECON1 register into SPDR register.
 SPDR = 0x1F;
 //wait until transmission is complete.
 while(!(SPSR)&(1<<SPIF)) {};
 //make PC5(chip select) pin high to signify completion of sending command.
 PORTC = (1<<5);

 //read the received data.
 return(SPDR);
}   

now how to print the uint8_t data received from this function in binary format?

Best Answer

itoa() will let you convert an int to a string representation in any radix from 2 to 36. I recommend sticking with 2, 8, or 16 for displaying binary data.

Related Topic