mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-03-21 09:11:00 +03:00
Fix error in CAN speed calculation
This commit is contained in:
@@ -165,7 +165,7 @@ void CAN_setup(uint16_t speed){
|
||||
CAN->MCR &=~ CAN_MCR_SLEEP; /* (3) */
|
||||
CAN->MCR |= CAN_MCR_ABOM; /* allow automatically bus-off */
|
||||
|
||||
CAN->BTR |= 2 << 20 | 3 << 16 | (6000/speed) << 0; /* (4) */
|
||||
CAN->BTR |= 2 << 20 | 3 << 16 | (6000/speed - 1); /* (4) */
|
||||
CAN->MCR &=~ CAN_MCR_INRQ; /* (5) */
|
||||
tmout = 16000000;
|
||||
while((CAN->MSR & CAN_MSR_INAK)==CAN_MSR_INAK) if(--tmout == 0) break; /* (6) */
|
||||
|
||||
@@ -544,8 +544,13 @@ void printu(uint32_t val){
|
||||
void printuhex(uint32_t val){
|
||||
addtobuf("0x");
|
||||
uint8_t *ptr = (uint8_t*)&val + 3;
|
||||
int8_t i, j;
|
||||
int8_t i, j, z=1;
|
||||
for(i = 0; i < 4; ++i, --ptr){
|
||||
if(*ptr == 0){ // omit leading zeros
|
||||
if(i == 3) z = 0;
|
||||
if(z) continue;
|
||||
}
|
||||
else z = 0;
|
||||
for(j = 1; j > -1; --j){
|
||||
uint8_t half = (*ptr >> (4*j)) & 0x0f;
|
||||
if(half < 10) bufputchar(half + '0');
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user