AT90CAN64 - How to change CAN baud rate at run time.

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Everyone,

 

I'm using AT90CAN64 and at90CANLIB_3_2. I defined #define CAN_BAUDRATE   500 // in kBit in the config.h file;

However, I need to be able to set/change CAN baud rate during run time.

Do you have any ideas how to change the CAN baud rate during run time?

 

Thank in advance,

Dennis

 

 

This topic has a solution.
Last Edited: Thu. Oct 19, 2017 - 03:20 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Everyone,

 

I guess I need to write a new function, for example:

 

// case of FOSC == 16000
U8 can_config_baud(U16 baud)
{
    Can_reset();

    switch (baud) {
        case 100:
            CANBT1 = 0x12;   // Tscl  = 10x Tclkio = 625 ns
            CANBT2 = 0x0C;   // Tsync = 1x Tscl, Tprs = 7x Tscl, Tsjw = 1x Tscl
            CANBT3 = 0x37;   // Tpsh1 = 4x Tscl, Tpsh2 = 4x Tscl, 3 sample points
            break;
        case 125:
            CANBT1 = 0x0E;   // Tscl  = 8x Tclkio = 500 ns
            CANBT2 = 0x0C;   // Tsync = 1x Tscl, Tprs = 7x Tscl, Tsjw = 1x Tscl
            CANBT3 = 0x37;   // Tpsh1 = 4x Tscl, Tpsh2 = 4x Tscl, 3 sample points
            break;
        case 200:
            CANBT1 = 0x08;   // Tscl  = 5x Tclkio = 312.5 ns
            CANBT2 = 0x0C;   // Tsync = 1x Tscl, Tprs = 7x Tscl, Tsjw = 1x Tscl
            CANBT3 = 0x37;   // Tpsh1 = 4x Tscl, Tpsh2 = 4x Tscl, 3 sample points
            break;
        case 250:
            CANBT1 = 0x06;   // Tscl  = 4x Tclkio = 250 ns
            CANBT2 = 0x0C;   // Tsync = 1x Tscl, Tprs = 7x Tscl, Tsjw = 1x Tscl
            CANBT3 = 0x37;   // Tpsh1 = 4x Tscl, Tpsh2 = 4x Tscl, 3 sample points
            break;
        case 500:
            CANBT1 = 0x06;   // Tscl = 4x Tclkio = 250 ns
            CANBT2 = 0x04;   // Tsync = 1x Tscl, Tprs = 3x Tscl, Tsjw = 1x Tscl
            CANBT3 = 0x13;   // Tpsh1 = 2x Tscl, Tpsh2 = 2x Tscl, 3 sample points
            break;
        case 1000:
            CANBT1 = 0x02;   // Tscl  = 2x Tclkio = 125 ns
            CANBT2 = 0x04;   // Tsync = 1x Tscl, Tprs = 3x Tscl, Tsjw = 1x Tscl
            CANBT3 = 0x13;   // Tpsh1 = 2x Tscl, Tpsh2 = 2x Tscl, 3 sample points
            break;
        default:
            break;
    }

    can_clear_all_mob();
    Can_enable();
    return 1;
}

 

Cheer!

Dennis