04-19-2017 03:49 PM
I have a routine in C where I create session set bus speed and start a loop which reads frame from the bus and logs the bus communication state using (nxReadState). The communication state always reads "nxCANCommState_ErrorPassive".
How do I fix this?
04-19-2017 04:49 PM
The communication state will enter Error Passive when the Receive Error Counter (REC) is greater than 127. The REC will increment by various amounts depending on what error was detected on the bus. The REC will also decrease by 1 upon the successful transmission of a complete frame.
If you appear to be reading data fine but stay in the Error Passive state, it could be that noise is occasionally causing a bit to be misinterpreted and generating an error. The re-transmission could then succeed. The most common cause of this problem is probably improper termination on the CAN bus. Check to ensure you have 60 Ohms total of termination.
Errors on the bus can also be read by using the Interface:Bus Errors to Input Stream property. An easy way to read errors on the bus is to open the XNET bus monitor, check the Bus Error Frames box, start the bus monitor, and then run your application. Any bus errors received will be shown including the current REC and TEC values.
04-20-2017 07:28 AM
Thanks JefeL for your insight.
I did change my termination resistor but that didn't help. I was able to log this through Bus Monitor without using my code per say.
Attach is the screenshot and log from bus monitor and also NI I/O trace log when I run my code.
Is there any other debugging ideas I can try out to get rid of this issue?
04-20-2017 08:21 AM
I see you are using CAN FD. Based on your log file I think we are running into the problem described here:
Troubleshooting CAN FD + BRS communications with NI-XNET devices
The sample point of the receiver is not matched with the sample point of your transmitter causing some frames to be misinterpreted and generate error frames. Find out what the bit timing settings are for your DUT (Both the arbitration phase and data phase) and try to match them with the XNET bus monitor custom baud rate settings.
Some of our customer have has success with the following settings. Keep in mind the important thing is to match your DUT but if those settings aren't known the settings below may help:
Arbitration Phase:
Data Phase:
04-20-2017 01:42 PM - edited 04-20-2017 01:42 PM
Thanks again JefeL.
Changing speed to custom speed for both CAN and CAN FD to the values you suggested worked from Bus Monitor. No more bus errors.
But, now I am replicating same in my C code using "nxAdvCANBaudRate_Set()" but it doesn't work.
Code snippet.
u32 baudRate; nxStatus_t ni_rc; //From nixnet.h //#define nxAdvCANBaudRate_Set(TimeQuantum, TimeSeg0, TimeSeg1, SyncJumpWidth) ( \ // (((u32)TimeQuantum) & 0x0000FFFF) | \ // (((u32)TimeSeg0 << 16) & 0x000F0000) | \ // (((u32)TimeSeg1 << 20) & 0x00700000) | \ // (((u32)SyncJumpWidth << 24) & 0x03000000) | \ // ((u32)0x80000000) ) baudRate = nxAdvCANBaudRate_Set(0,54,23,15); ni_rc = nxSetProperty(outSession, nxPropSession_IntfBaudRate, sizeof baudRate, &baudRate); baudRate = nxAdvCANBaudRate_Set(0, 13, 4, 4); ni_rc = nxSetProperty(outSession, nxPropSession_IntfCanFdBaudRate, sizeof baudRate, &baudRate);
Any ideas?
04-20-2017 01:56 PM
The hex value shown in the upper right corner can be copied an placed directly in your code.
It is important to note that the value is 64 bits. The Interface:CAN:64bit FD Baud rate was introduced to supersede the old FD Baud rate property but is backwards compatible with a 32 bit value for normal CAN operations. Take a look at the property description on page 5-280 to see how the new values are interpreted.
04-21-2017 09:09 AM
I am having hard time passing correct values to these properties in C. Do you have sample C code which shows how to set these baud rate properties "nxPropSession_IntfBaudRate64" and "nxPropSession_IntfCanFdBaudRate64" with custom baud rate?
04-21-2017 01:42 PM
There are multiple ways to set the baud rate. Below I set a default baud rate, set a custom baud rate with a hex value directly from the bus monitor, and call a helper macro to define the constant in a similar way to the nxAdvCANBaudRate_Set macro in XNET.h.
The macro details are define above:
And I have attached the entire shipping example that I have modified to use CAN FD.
04-24-2017 12:13 PM - edited 04-24-2017 12:14 PM
Thanks a lot Jeff L for writing up that macro.
Setting baud rate worked fine with those macros I see frames received from the controller. Now the issue I am seeing is whenever I go write to the bus(nxWriteFrame) right after that I see an error-passive state which later converts to bus-off state.
Not sure now what is this issue. Attached is a small subset of what my program does as a whole.
I have also attached the NI I/O trace log.
Looks like there is a bug in the NI I/O trace log it does not display the 64 bit value passed for of the 64 bit properties (nxPropSession_IntfBaudRate64 and nxPropSession_IntfCanFdBaudRate64).
04-24-2017 04:29 PM
It is difficult for me to say without a ECU to test your code against. When I run your application against the bus monitor it appears to work fine (I added some extra printf calls for debugging):
All the transmitted frames were sent and detected without any bus errors.
I deciphered the stateValue returned from nxReadState (0x00F80402) and it appears to be Buss Off (0x2), Bit 1 Error (0x4), and TEC of 0xF8. Bit1 errors indicate that the interface tried to send a recessive bit but monitored a dominant value.
Would the ECU continue to transmit if it looses arbitration through a bug or any other known issues? Is there anything else on the bus? Are you able to run your program fine against the bus monitor?