Fix error in CAN speed calculation

This commit is contained in:
eddyem
2020-04-30 01:18:39 +03:00
parent 131f6fab44
commit bc7a9aacc5
13 changed files with 524 additions and 45 deletions

View File

@@ -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) */

View File

@@ -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.