Electronics > Microcontrollers

CAN problem with PIC18F25K80 and SN65HVD231

(1/2) > >>

Spekkio:
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 ?

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

Spekkio:
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."
--- End quote ---

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

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

Spekkio:

--- Quote from: peter_mcc 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

--- End quote ---

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.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod