This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS470 different baudrate configuration

hi sir,

what ever the values created by the HALCoGen code generator , that is working for different baudrates. but now i am facing one problem.
in my program for 100Kbps , and 125Kbps the code is working properly.

when i am configure my code 33.333Kbps & 83.333Kbps its not working properly.  ( for checking purpose i try to transmit the data at 8 times in loop. but its transmitting only one time.) 
i attached my code in downside. in that program, first my code is run in 500Kbps. after that i configure my code for 33.333Kbps and 83.333Kbps

in 500Kbps its transmit the data properly. but when i configure my code to 33.333Kbps and 83.333Kbps , its not transmit every time. 
in my code i am using the two for loop(). in that first for loop(), at the last time [i=7 (at 8th time)] only its transmit only one time. before that its not transmit. in the 2nd for loop() , its transmit the last time [ i=2 ( at 3rd time ) ] . and some times its not transmitted. 

i dont know where the problem occur in my code. can u please tell me the solution for this problem. i attached my code for verification purpose in the below.



PROGRAM:

#include "sys_common.h"
#include "system.h"

#include "can.h"
#include "esm.h"

#define D_SIZE 8
uint8 tx_data[D_SIZE] = {'H','E','R','C','U','L','E','S'};
uint8 tx2_data[D_SIZE] = {'1','s','t','L','O','O','P'};
uint8 tx1_data[D_SIZE] = {'T','I','G','E','R'};
uint8 rx_data[D_SIZE] = {0};
int i=0;

void can_baud_33kbps(void); // checked (no working) at last time only working
void can_baud_83kbps(void); // checked (no working) at last time only working
void can_baud_100kbps(void); // checked (working)
void can_baud_125kbps(void); // checked (working)

void main(void)
{

canInit();
canTransmit(canREG1, canMESSAGE_BOX2, tx_data);

while(!canIsRxMessageArrived(canREG1, canMESSAGE_BOX1));
canGetData(canREG1, canMESSAGE_BOX1, rx_data);

if(rx_data[0] == 0x61)
{
can_baud_33kbps();
can_baud_83kbps();

}

for(i=0;i<8;) // FOR LOOP 1
{
canTransmit(canREG1, canMESSAGE_BOX2, tx2_data);
i++;
}

for(i=0;i<3;i++) // FOR LOOP 2
{
canTransmit(canREG1, canMESSAGE_BOX2, tx1_data);
}

canTransmit(canREG1, canMESSAGE_BOX2, tx_data);

while(1);

}




void can_baud_33kbps(void)
{


canREG1->CTL = 0x00000000U
| 0x00000000U
| 0x00021443U | (1<<2) | (1<<3) ;

/** - Clear all pending error flags and reset current status */
canREG1->ES = canREG1->ES;

/** - Assign interrupt level for messages */
canREG1->INTMUXx[0U] = 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U;

canREG1->INTMUXx[1U] = 0x00000000U;

/** - Setup auto bus on timer period */
canREG1->ABOTR = 0U;

/** - Initialize message 1
* - Wait until IF1 is ready for use
* - Set message mask
* - Set message control word
* - Set message arbitration
* - Set IF1 control byte
* - Set IF1 message number
*/
while ((canREG1->IF1STAT & 0x80U) ==0x80U)
{
} /* Wait */


canREG1->IF1MSK = 0xC0000000U | ((0x3FFFFFFFU & 0x1FFFFFFFU) << 0U);
canREG1->IF1ARB = 0x80000000U | 0x40000000U | 0x00000000U | ((1U & 0x1FFFFFFFU) << 0U);
canREG1->IF1MCTL = 0x00001080U | 0x00000400U | 8U;
canREG1->IF1CMD = 0xF8;
canREG1->IF1NO = 1;

/** - Initialize message 2
* - Wait until IF2 is ready for use
* - Set message mask
* - Set message control word
* - Set message arbitration
* - Set IF2 control byte
* - Set IF2 message number
*/
while ((canREG1->IF2STAT & 0x80U) ==0x80U)
{
} /* Wait */

canREG1->IF2MSK = 0xC0000000U | ((0x3FFFFFFFU & 0x1FFFFFFFU) << 0U);
canREG1->IF2ARB = 0x80000000U | 0x40000000U | 0x20000000U | ((2U & 0x1FFFFFFFU) << 0U);
canREG1->IF2MCTL = 0x00001080U | 0x00000000U | 8U;
canREG1->IF2CMD = 0xF8;
canREG1->IF2NO = 2;


/** - Setup IF1 for data transmission
* - Wait until IF1 is ready for use
* - Set IF1 control byte
*/
while ((canREG1->IF1STAT & 0x80U) ==0x80U)
{
} /* Wait */
canREG1->IF1CMD = 0x87;

/** - Setup IF2 for reading data
* - Wait until IF1 is ready for use
* - Set IF1 control byte
*/
while ((canREG1->IF2STAT & 0x80U) ==0x80U)
{
} /* Wait */
canREG1->IF2CMD = 0x17;

/** - Setup bit timing
* - Setup baud rate prescaler extension
* - Setup TSeg2
* - Setup TSeg1
* - Setup sample jump width
* - Setup baud rate prescaler
*/
canREG1->BTR = (3U << 16U) |
((4U - 1U) << 12U) |
(((1U + 4U) - 1U) << 8U) |
((4U - 1U) << 6U) |
43U;

/** - Setup TX pin to functional output */
canREG1->TIOC = 0x0000004CU;

/** - Setup RX pin to functional input */
canREG1->RIOC = 0x00000048U;

/** - Leave configuration and initialization mode */
canREG1->CTL &= ~0x00000041U;

}



void can_baud_83kbps(void)
{


canREG1->CTL = 0x00000000U
| 0x00000000U
| 0x00021443U | (1<<2) | (1<<3) ;

/** - Clear all pending error flags and reset current status */
canREG1->ES = canREG1->ES;

/** - Assign interrupt level for messages */
canREG1->INTMUXx[0U] = 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U;

canREG1->INTMUXx[1U] = 0x00000000U;

/** - Setup auto bus on timer period */
canREG1->ABOTR = 0U;

/** - Initialize message 1
* - Wait until IF1 is ready for use
* - Set message mask
* - Set message control word
* - Set message arbitration
* - Set IF1 control byte
* - Set IF1 message number
*/
while ((canREG1->IF1STAT & 0x80U) ==0x80U)
{
} /* Wait */


canREG1->IF1MSK = 0xC0000000U | ((0x3FFFFFFFU & 0x1FFFFFFFU) << 0U);
canREG1->IF1ARB = 0x80000000U | 0x40000000U | 0x00000000U | ((1U & 0x1FFFFFFFU) << 0U);
canREG1->IF1MCTL = 0x00001080U | 0x00000400U | 8U;
canREG1->IF1CMD = 0xF8;
canREG1->IF1NO = 1;

/** - Initialize message 2
* - Wait until IF2 is ready for use
* - Set message mask
* - Set message control word
* - Set message arbitration
* - Set IF2 control byte
* - Set IF2 message number
*/
while ((canREG1->IF2STAT & 0x80U) ==0x80U)
{
} /* Wait */

canREG1->IF2MSK = 0xC0000000U | ((0x3FFFFFFFU & 0x1FFFFFFFU) << 0U);
canREG1->IF2ARB = 0x80000000U | 0x40000000U | 0x20000000U | ((2U & 0x1FFFFFFFU) << 0U);
canREG1->IF2MCTL = 0x00001080U | 0x00000000U | 8U;
canREG1->IF2CMD = 0xF8;
canREG1->IF2NO = 2;


/** - Setup IF1 for data transmission
* - Wait until IF1 is ready for use
* - Set IF1 control byte
*/
while ((canREG1->IF1STAT & 0x80U) ==0x80U)
{
} /* Wait */
canREG1->IF1CMD = 0x87;

/** - Setup IF2 for reading data
* - Wait until IF1 is ready for use
* - Set IF1 control byte
*/
while ((canREG1->IF2STAT & 0x80U) ==0x80U)
{
} /* Wait */
canREG1->IF2CMD = 0x17;

/** - Setup bit timing
* - Setup baud rate prescaler extension
* - Setup TSeg2
* - Setup TSeg1
* - Setup sample jump width
* - Setup baud rate prescaler
*/
canREG1->BTR = (1U << 16U) |
((6U - 1U) << 12U) |
(((1U + 6U) - 1U) << 8U) |
((4U - 1U) << 6U) |
4U;

/** - Setup TX pin to functional output */
canREG1->TIOC = 0x0000004CU;

/** - Setup RX pin to functional input */
canREG1->RIOC = 0x00000048U;

/** - Leave configuration and initialization mode */
canREG1->CTL &= ~0x00000041U;

}
regards
Arun kumar
  • You cannot change the baud rate on a CAN bus. All devices on the bus must be using the same baud rate, otherwise the devices at a different baud rate will identify the frame as having errors.
  • hi sir,

    in my code initially i am configure at 500Kbps. after that i am change the baudrate at 125Kbps or 100Kbps. this 100 & 125Kbps both are working properly. when i configure less than 100Kbps (<100Kbps) ,then only the problem occur.

    if the frame errors occur, because of changing the baudrate means its not work in the 100 & 125 Kbps also. but its working properly.
    when i am change to 33 & 83 Kbps then only problem arise. here also i checked in the debugging window. no errors are occured for 33 &83 Kbps.

    in 33 & 83Kbps also its working, but not correctly. if i use a simple transmit function means its not transmitted. if i transmit more num times using loop , its transmitted at the last time of the loop(). i dont know where the prob arise. if i debug step by step also , its not showing any error.
    if its working only last time means , where the code get problem. if error occur means its not transmit the data properly, but error is also not generated.

    i dont know the solution for this problem , can you tell me the solution for this.

    regards
    Arun kumar.N
  • You have to have at least two nodes on the network. What else is on your network? Are you changing the baud rate of all nodes on the network? Are the other nodes capable of acknowledging CAN frames at 33 and 83 Kbps?
  • hi sir,

    i have two nodes in the network. In DCAN1 (node1 : messageobject-1 & node 2 : messageobject-2). messageobject1 for receiving , and messgaeobject1 for transmitting.

    i change the baudrate of all the nodes in the network. i attched my main code in the below side.

    PROGRAM:

    #include "sys_common.h"
    #include "system.h"

    #include "can.h"
    #include "esm.h"

    #define D_SIZE 8
    uint8 tx_data[D_SIZE] = {'H','E','R','C','U','L','E','S'};
    uint8 tx2_data[D_SIZE] = {'1','s','t','L','O','O','P'};
    uint8 tx1_data[D_SIZE] = {'T','I','G','E','R'};
    uint8 rx_data[D_SIZE] = {0};
    uint8 rx1_data[D_SIZE ]= {0};
    int i=0;

    void can_baud_33kbps(void); // checked (no working) at last time only working
    void can_baud_83kbps(void); // checked (no working) at last time only working
    void can_baud_100kbps(void); // checked (working)
    void can_baud_125kbps(void); // checked (working)
    void can_init();

    void main(void)
    {
    canInit();

    canTransmit(canREG1, canMESSAGE_BOX2, tx_data);

    while(!canIsRxMessageArrived(canREG1, canMESSAGE_BOX1));
    canGetData(canREG1, canMESSAGE_BOX1, rx_data);

    if(rx_data[0] == 0x61)
    {
    can_baud_33kbps();
    }

    for(i=0;i<8;) // FORLOOP-1
    {
    canTransmit(canREG1, canMESSAGE_BOX2, tx2_data);
    i++;
    }

    /* for(i=0;i<3;) // FORLOOP-2
    {
    canTransmit(canREG1, canMESSAGE_BOX2, tx1_data);
    i++;
    }*/

    while(1);
    }