CAN Transmit not Working in Aurix TC375 Kit

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User21321
Level 2
Level 2
First like received
Hello!
I follow CAN Loop back code example and it works perfectly fine on my Aurix TC375 kit. But when i change it from Loopback mode to normal mode and set RX and TX pins. Then it is not working.


I am using following setting for CAN Transmit but it is not working. It stuck in the while loop of CanTransmit block:

#define TX_PIN IfxCan_TXD00_P20_8_OUT
#define RX_PIN IfxCan_RXD00B_P20_7_IN

typedef struct
{
IfxCan_Can_Config canConfig; /* CAN module configuration structure */
IfxCan_Can canModule; /* CAN module handle */
IfxCan_Can_Node canSrcNode; /* CAN source node handle data structure */
IfxCan_Can_NodeConfig canNodeConfig; /* CAN node configuration structure */
IfxCan_Filter canFilter; /* CAN filter configuration structure */
IfxCan_Message txMsg; /* Transmitted CAN message structure */
IfxCan_Message rxMsg; /* Received CAN message structure */
} McmcanType;

McmcanType stg_CanCtrl;

void Can_Init(void)
{
const IfxCan_Can_Pins pins =
{
&TX_PIN, IfxPort_OutputMode_pushPull,
&RX_PIN, IfxPort_InputMode_pullUp,
IfxPort_PadDriver_cmosAutomotiveSpeed1
};

IfxCan_Can_initModuleConfig(&stg_CanCtrl.canConfig, &MODULE_CAN0);

IfxCan_Can_initModule(&stg_CanCtrl.canModule, &stg_CanCtrl.canConfig);

IfxCan_Can_initNodeConfig(&stg_CanCtrl.canNodeConfig, &stg_CanCtrl.canModule);

stg_CanCtrl.canNodeConfig.baudRate.baudrate = CAN_BUADRATE;
stg_CanCtrl.canNodeConfig.nodeId = IfxCan_NodeId_0;
stg_CanCtrl.canNodeConfig.pins = &pins;
stg_CanCtrl.canNodeConfig.frame.type = IfxCan_FrameType_transmit;
IfxCan_Can_initNode(&stg_CanCtrl.canSrcNode, &stg_CanCtrl.canNodeConfig);

}

void CanTransmit(void)
{

IfxCan_Can_initMessage(&stg_CanCtrl.txMsg);

stg_CanData.DataType.u8_Data[0] = 0;
stg_CanData.DataType.u8_Data[1] = 0;
stg_CanData.DataType.u8_Data[2] = 0;
stg_CanData.DataType.u8_Data[3] = 0;
stg_CanData.DataType.u8_Data[4] = 0;
stg_CanData.DataType.u8_Data[5] = 0;
stg_CanData.DataType.u8_Data[6] = 0;
stg_CanData.DataType.u8_Data[7] = 0;

stg_CanCtrl.txMsg.messageId = CAN_ID;

while( IfxCan_Status_notSentBusy ==
IfxCan_Can_sendMessage(&stg_CanCtrl.canSrcNode, &stg_CanCtrl.txMsg, &stg_CanData.DataType.u32_Data[0]) )
{
}
}
0 Likes
21 Replies
TBencher
Level 6
Level 6
25 solutions authored 25 likes received 5 questions asked
Hi abkakar,

is that the whole init and transmission code? If you compare it with the example code, there seems like a little bit more to be covered there.
Try to disable loopback mode in the example code first to test proper transmission at the TX pin.

You should see transmitted messages easily with a scope connected to it. If you put the transmit function call into the while loop of C0, you should see
TX sending messages all the time. All this assuming you have no transmitter connected to it.


Regards,

Jens
0 Likes
TBencher
Level 6
Level 6
25 solutions authored 25 likes received 5 questions asked
Better solution would be sending messages over a timer interrupt routine. Otherwise, C0 would get stucked in waiting for completed CAN transmissions.

Regards,

Jens
0 Likes
User21321
Level 2
Level 2
First like received
Hey JensM!
Thank you very much for your reply.

In the MCMCAN example, loop back mode is used and for that node 0 is declared as transmitter and node 1 as receiver. Similarly two interrupts are also used for both Tx and Rx.

I made my code from the example code by doing following things:

1: Node 0 as Tx
2: Remove the interrupt on Tx
3: Remove Node 1 portion
4: In the main.c , I am send Tx request by using a timer of 1 sec.

But the code stuck in the sending Tx block and it does not work. I check by oscilloscope as well. There is no signal over there.

Now i find another thing as well.
If i use Node 0 as Tx with external loop back mode and Node 1 as Rx with internal Loop back mode, then I can see the Tx signal on the Tx pin by Oscilloscope.
I made external loop back by:
g_mcmcan.canSrcNode.node->NPCR.B.LOUT = 1;
g_mcmcan.canSrcNode.node->NPCR.B.LBM = 0;

Hence in external loop back mode, i can see the signal on Tx pins. But in normal mode, I can't. What's missing in my code.?
Kindly help me in this regard.
Thanks
0 Likes
TBencher
Level 6
Level 6
25 solutions authored 25 likes received 5 questions asked
Hi abkakar,

please drop me your project to info@tbench-solutions.com . We will have a quick look on it.


Regards,

Jens
0 Likes
User21321
Level 2
Level 2
First like received
Dear JensM!
Please check your email. I have already sent you my project.
If you don't get it then please check your spam folder. The title of email is "MCMCAN TX Problem"
Regards
0 Likes
TBencher
Level 6
Level 6
25 solutions authored 25 likes received 5 questions asked
Hi abkakar,

I have received your mail. We will check this during next week.


Regards,

Jens
0 Likes
User21487
Level 1
Level 1
First solution authored 5 replies posted First reply posted
JensM is right, some settings are missing.
Maybe better to start with the full example and reduce slightly step by step?

For example I'm missing:
- g_mcmcan.canNodeConfig.txConfig.txMode
- g_mcmcan.canNodeConfig.txConfig.txBufferDataFieldSize <- how many bytes to send

In general you are right. Switching to non-loopmode means
instead of:

g_mcmcan.canNodeConfig.busLoopbackEnabled = TRUE;

use:

g_mcmcan.canNodeConfig.pins = &pins;


Please note, in the example there are dst and src node configured - even loopmode is set twice and should be changed accordingly.

BR
0 Likes
User21321
Level 2
Level 2
First like received
Dear Eric!
Thank you very much for your reply.

TxMode and txBufferDataFieldSize etc are already declared in "IfxCan_Can_initNodeConfig" function. So, i guess there is no need to declare them again.

IfxCan_Can_initNodeConfig(&g_mcmcan.canNodeConfig, &g_mcmcan.canModule);


Thanks
0 Likes
Harvey
Employee
Employee
Hi abkakar,

On my side, I didn't saw any problem in your code.
Please check below contents

1. Which AURIX TC375 kit is used ? (e.g TriBoard TC3x5)
Please let me know exact board name and version.

2. How did you configure HW connection for CAN test ? Is AURIX TC375 connect with external CAN test device (e.g CANoe) ? So, you only configured TX code on AURIX TC375. Is it correct ?
In case of TriBoard TC3x5, you can test 2 CAN channels. So, If you wants to test CAN, you have to connect both CANH and CANL on CAN Connector.
Of course, SW for for 2 CAN channels also have to be implemented.
In case of TC3x5 Triboard, 2 CAN channels are available as below
- CAN0 transceiver : Connect P20.7 with CAN RXD, Connect P20.8 with CAN TXD
- CAN1 transceiver : Connect P23.0 with CAN RXD, Connect P23.1 with CAN TXD

3. What is CAN baud rate ?
If AURIX TC375 connect with external CAN test device, did you configure same baud rate ?

4. Did you check "Protocol Status Register" ? Please check this register.

5. Did you check CAN Tx signal after remove while loop ?

Thanks.
0 Likes
lock attach
Attachments are accessible only for community members.
User21321
Level 2
Level 2
First like received
Dear Harvey!
Thank you very much for your reply.
Please find the attached code and scenarios.

I am using Aurix TC375 Lite Kit. In this kit CANH and CANL are attached to P20.7 and P20.8. To use CAN module we need to set CAN STB pin LOW.
Currently I am only checking CAN signal on Oscilloscope.

I start from MCMCAN example. Internal loop back mode was working fine. Then I change to external loop back mode. That also work fine and I can see CAN output on oscilloscope.

Finally when i try to use normal mode with Node 0 as transmitter then I can not see any output and debugger shows that code is stuck in CAN transmit block.
I am using debugger mode in Aurix Development Studio and in this debugger I can not see the values of registers.

Kindly check my attachments. You will understand all of the situation.
Regards
0 Likes
TBencher
Level 6
Level 6
25 solutions authored 25 likes received 5 questions asked
Hi all,

we have worked out a complete functioning CAN example for abkakar.
Maybe, there are still some basic configuration issues in his project.


Regards,

Jens
0 Likes
TBencher
Level 6
Level 6
25 solutions authored 25 likes received 5 questions asked
Here is the transmit output for it.

5049.attach


Regards,

Jens

Hi Jens,

thank you for posting the oscilloscope picture.

May I ask which was the baud-rate detected by your oscilloscope?

Reason: I noticed that, when setting baudrate = 250000, the actual baudrate output on CAN is 500,000 baud, which is double.

0 Likes
User21321
Level 2
Level 2
First like received
Thank you very much Mr. Jens for your help. My issue is resolved by your code.
The only problem was that I was not checking the CAN signal via CANOE or other CAN instrument. I was just checking on simple oscilloscope.
When i connect CANOE then it was working perfectly.
0 Likes
lock attach
Attachments are accessible only for community members.
User21321
Level 2
Level 2
First like received
Here is my code for Aurix TC375 Lite Kit for Tx and Rx on Node 0.

first of all, thank you for providing this code. Is definitely helpful.
Anyway I am able to use correctly only the sending functionality: tested connecting my TC375 to Arduino equipped with CAN-shield.
I have problem with receiving messages from arduino with the TC375.
Of course the connection is checked with other device so i am sure that arduino send and the TC375 have issue in receiving.
Can you suggest how to modify correctly your code for receiving any can messages?

Tank you in advance for support!!

Bests.

0 Likes
TBencher
Level 6
Level 6
25 solutions authored 25 likes received 5 questions asked
You're welcome.


Regards,

Jens
0 Likes
Igol
Level 1
Level 1
First like received First reply posted Welcome!

Sorry to drop like this, so in the end you need to activate the CAN transceiver or not? I mean, you need to put CAN_STB = 0 in some way? If yes, how?

Thank you very much!

Yes, you must set the Silent pin of the transceiver to LOW in order to communicate on CAN.

0 Likes
MarkusNoll
Employee
Employee
25 replies posted 10 likes received 25 sign-ins

CAN_STB is connected to P20.6 and can be controlled like a GPIO pin.

It is necessary that the CAN trx is activated, as the uC is sensing it's own transmitting output in realtime back over the CAN_RXD signal. If there is no feedback (because can trx is inactive), the uC thinks that the bus is blocked.

0 Likes
DavideCavaliere
Level 1
Level 1
First reply posted First like given Welcome!

Hello,

thank you for posting the code.

I was able to successfully run you code. However, I found out that the baudrate to be configured in "stg_CanCtrl.canNodeConfig.baudRate.baudrate = CAN_BUADRATE;" should be HALF of the baudrate on CAN.

Example: when setting "250000", the baudrate of the signal was 500kbaud.

I have Googled about this, and it seems that this bug was present also in the past, then it was fixed for TC2xx, but still now it appears on TC375 Lite Kit board.

I hope this info will help other people that find issues with your code.

0 Likes