mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-03-21 09:11:00 +03:00
USB CAN sniffer: works as broadcast listener & can write someth; TODO: add filters
This commit is contained in:
14
F0-nolib/Snippets/printuhex.c
Normal file
14
F0-nolib/Snippets/printuhex.c
Normal file
@@ -0,0 +1,14 @@
|
||||
// print 32bit unsigned int as hex
|
||||
void printuhex(uint32_t val){
|
||||
addtobuf("0x");
|
||||
uint8_t *ptr = (uint8_t*)&val + 3;
|
||||
int8_t i, j;
|
||||
for(i = 0; i < 4; ++i, --ptr){
|
||||
if(*ptr == 0 && i != 3) continue; // omit leading zeros
|
||||
for(j = 1; j > -1; --j){
|
||||
uint8_t half = (*ptr >> (4*j)) & 0x0f;
|
||||
if(half < 10) bufputchar(half + '0');
|
||||
else bufputchar(half - 10 + 'a');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user