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;
}
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