0x11. C - Printf

0 views
Skip to first unread message

Faith Lienhard

unread,
Aug 4, 2024, 8:30:30 PM8/4/24
to mondfirbimas
Ican specify the number of digits like printf("%08x", ...). But I'd like to automatically adjust the number of digits according to the data type, (e.g, long (64 bits) should automatically have 64/4=16 digits). Is there a way to do so? Thanks.

Note that the lack of commas between the strings are not a mistake. This is a formatting technique that uses a feature in C called "automatic string concatenation", such that the three strings will get slapped together. The PRIx8 is just a convenience which means the correct formatting for an 8 bit hexadecimal value.


I am working with the CC1101 and using the examples posted by TI. I am using the Link2 example and I have modified it a little to suit my needs. I am trying to program the board to read data from the UART and transmit that data. However, when I look at the data that I have stored in the TXBuffer array, the data is appended with an extra byte on the end of each array element (usually 10, 01, 2E, or something else nonsensical). I check this by writing out the TXBuffer to the a terminal after I have filled it with data. I then transmit the buffer and write out the data again. On the receive end, I find that I can sometimes receive the correct data, but there is again another extra byte appended on each element (also checked by writing to the terminal).


It seems to me that there is something wrong with the way you write to the txBuffer array. You should check what values you actually write to the TXFIFO register and what you read out of the RXFIFO on the reciever.


I don't know if it is the CC1101 itself. If your array is from the type unsigned char or char, there cannot even be an extra byte, because an char is just one byte. Please place your code, so we can see what you exactly mean


Of course an byte is 8 bits, but maybe it is more than a byte long, so please verify. To do so, try to initialize all buffer elements to 0xFFFF with a simple for loop and print it out with an \r\n between each element. If this results in a long range of 0xFFFF, the buffer elements are longer than 8 bits (probably 16, but that does not matter). If that is so, the initialization of the buffers should be done with the type UINT8 instead of BYTE.


But than it could not be possible to print out more than 2 hexadecimals for each element. Can you fill the elements as mentioned in me previous post ? This will determine the amount of bits in one element.


I dont know the exact values for your hardware, but is always good to start at a slower baud rate. However this problems seems not to be caused by the baudrate, but you should try to set it on 9600 Kbaud (bits per second). The baudrate should be the same in the terminal as well as in the microcontroller.


Thank you so much for being so patient. This was a really stupid mistake on my part. printf accepts integer arguments, but I was only sending one byte of data. To correctly output this, I should have been doing this:

3a8082e126
Reply all
Reply to author
Forward
0 new messages