- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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]) )
{
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Jens
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
please drop me your project to info@tbench-solutions.com . We will have a quick look on it.
Regards,
Jens
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have received your mail. We will check this during next week.
Regards,
Jens
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
we have worked out a complete functioning CAN example for abkakar.
Maybe, there are still some basic configuration issues in his project.
Regards,
Jens
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Jens
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Tags:
- User21321
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Jens
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, you must set the Silent pin of the transceiver to LOW in order to communicate on CAN.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.