Author Topic: CAN problem with PIC18F25K80 and SN65HVD231  (Read 5212 times)

0 Members and 1 Guest are viewing this topic.

Offline SpekkioTopic starter

  • Regular Contributor
  • *
  • Posts: 94
  • Country: se
CAN problem with PIC18F25K80 and SN65HVD231
« on: December 07, 2011, 11:03:31 am »
I have a problem with CAN communication, I have two devices, one of them is sending and the other one is receiving. I get data out on the bus that I can see with an oscilloscope, and I also get data on CANRX on the receiving side so the transceiver is working on both sides. But both the receiving side and the transmitting side is counting up the TXERRCNT and RXERRCNT, never counts down. And the receiving side is not getting any data in the registers. What is the problem ? I have one output RB3 which is connected via an 100k resistor to the transceivers(SN65HVD231) Rs pin. Like it says in the datasheet. It should be low-level when ON, and high level when in sleep mode. I got the receiving side to work one time when I set RB3 and input, but then I restarted the program and it did not work anymore. I don't understand... ???

The receiving side is counting up RXERRCNT, and transmitting side TXERRCNT, I have not mixed up the programs. Also I did not forget 120ohm resistors on the CAN bus.

I was thinking, maybe because I run the receiving side in debug mode, with a breakpoint in the receive function to see if the MCU caught a message. Maybe the debug side is slower than the transmitting side witch is running in Release ? Also could it be a problem with the transceiver, because I get TXERRCNT and TXREQ is never cleared, the MCU think the bus is busy ? Do I need pull-ups maybe ?
 

Offline SpekkioTopic starter

  • Regular Contributor
  • *
  • Posts: 94
  • Country: se
Re: CAN problem with PIC18F25K80 and SN65HVD231
« Reply #1 on: December 08, 2011, 11:21:16 am »
Problem is not fixed :/ Though I seem to have removed the problem with TXERRCNT and RXERRCNT counting up. They stay on zero.
TX side is now transmitting, meaning the program gets out of the while(TXREQ); loop completely. But the receiving side is not getting any data at all, it is like it just ignores what is happening on the CANRX pin.

There are too many registers, ID, Filters etc, I can't get a good overview what they all do. The datasheet doesn't really explain what they do, I'm reading a CAN protocol specification, see if I can get a better understanding.

Been working on it for a week now. Probably something simple :p
« Last Edit: December 08, 2011, 11:54:56 am by Spekkio »
 

Offline SpekkioTopic starter

  • Regular Contributor
  • *
  • Posts: 94
  • Country: se
Re: CAN problem with PIC18F25K80 and SN65HVD231
« Reply #2 on: December 08, 2011, 02:13:58 pm »
I got the receiving side to accept messages when running in Error Recognition mode! But I dont want to run in this mode all the time, the program should work in a normal way ofcourse. Maybe I have just configured the filters wrong.

Quote
"The module can be set to ignore all errors and receive
any message. In functional Mode 0, the Error Recognition
mode is activated by setting the RXM<1:0> bits in
the RXBnCON registers to ‘11’. In this mode, the data
which is in the message assembly buffer until the error
time, is copied in the receive buffer and can be read via
the CPU interface."

RXB0CONbits.RXM0 = 1; // Error recognition mode
RXB0CONbits.RXM1 = 1;
RXB1CONbits.RXM0 = 1;
RXB1CONbits.RXM1 = 1;
 

Offline peter_mcc

  • Contributor
  • Posts: 40
Re: CAN problem with PIC18F25K80 and SN65HVD231
« Reply #3 on: December 09, 2011, 04:02:40 am »
Do you have a 100 ohm (?) resistor across the CAN-H CAN-L lines? CAN won't work unless the bus is terminated. In theory you need one at either end but I found for quick internal testing one in the middle would work with 2m of cable. For production you'd want to do it properly...
peter
 

Offline SpekkioTopic starter

  • Regular Contributor
  • *
  • Posts: 94
  • Country: se
Re: CAN problem with PIC18F25K80 and SN65HVD231
« Reply #4 on: December 09, 2011, 07:34:41 am »
Do you have a 100 ohm (?) resistor across the CAN-H CAN-L lines? CAN won't work unless the bus is terminated. In theory you need one at either end but I found for quick internal testing one in the middle would work with 2m of cable. For production you'd want to do it properly...
peter

Yes, I have 120ohm.

It works in error detection mode as I described above. So I think it's probably something with how I configured the filters.
 

Offline SpekkioTopic starter

  • Regular Contributor
  • *
  • Posts: 94
  • Country: se
Re: CAN problem with PIC18F25K80 and SN65HVD231
« Reply #5 on: December 12, 2011, 10:34:34 am »
I think I solved it now, it was a problem with the filters/masks. There are alot of filter and mask registers, and settings how they can be used.
 

Offline SpekkioTopic starter

  • Regular Contributor
  • *
  • Posts: 94
  • Country: se
Re: CAN problem with PIC18F25K80 and SN65HVD231
« Reply #6 on: December 13, 2011, 11:04:54 am »
Ok i fixed it now :)

Filter is set with RXFnSIDH, RXFnSIDL. If the mask registers are set to 0xFF the entire filter is used.
RXMnSIDH, RXMnSIDL = 0xFF. That means the receive buffers will only accept messages that are directly equal to the filters.

So messages that are transmitted with these TX regs
TXB0SIDH = 0x56
TXB0SIDL = 0x76
TXB0DLC = 0x04; // Data length 4 bytes. Bit 6 TXRTR=0.
TXB0D0 = t_1;
TXB0D1 = t_2;
TXB0D2 = h_1;
TXB0D3 = h_2;

will only be accepted by the CAN receiver that has the filter

RXF0SIDH = 0x56
RXF0SIDL = 0x76

If the mask is 0xFF for that filter.
RXM0SIDH = 0xFF
RXM0SIDL = 0xFF

The bits in the mask activates wich bits in the filter shall be used. So if you have the mask 0xF0 only the most significant nibble of the filter will be used.

Also look at what RXB0CONbits.RXM0, RXB0CONbits.RXM1 are set to.
Standard ID or Extended ID. I only use standard ID, but I guess if Extended ID is used also the RXFnEIDH, RXFnEIDL filters are used. Also look at the RXF0SIDLbits.EXIDEN bit, should be zero when using only Standard ID.
« Last Edit: December 13, 2011, 11:10:50 am by Spekkio »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf