Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

NI XNET : nxReadState returns the communication state as error positive(nxCANCommState_ErrorPassive) right after i initialize and create session

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?  

0 Kudos
Message 1 of 13
(5,365 Views)

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.

Jeff L
National Instruments
0 Kudos
Message 2 of 13
(5,352 Views)

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?

 

0 Kudos
Message 3 of 13
(5,318 Views)

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:

ArbPhase.PNG

Data Phase:

DataPhase.PNG

Jeff L
National Instruments
Message 4 of 13
(5,306 Views)

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.

 

NI I/O screenshot

 

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?

 

 

0 Kudos
Message 5 of 13
(5,299 Views)

The hex value shown in the upper right corner can be copied an placed directly in your code.

HexCode.PNG

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.

Jeff L
National Instruments
0 Kudos
Message 6 of 13
(5,295 Views)

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?

0 Kudos
Message 7 of 13
(5,280 Views)

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.

BaudRateOptoins.PNG

The macro details are define above:

BaudRateMacro.PNG

 

And I have attached the entire shipping example that I have modified to use CAN FD.

Jeff L
National Instruments
Message 8 of 13
(5,269 Views)

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).

 

Download All
0 Kudos
Message 9 of 13
(5,242 Views)

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):

FirstRunOfCode.PNG

 

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?

Jeff L
National Instruments
0 Kudos
Message 10 of 13
(5,230 Views)