|
|
View previous topic :: View next topic |
Author |
Message |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
Problem with can bus |
Posted: Mon Jun 15, 2015 7:51 am |
|
|
Greetings! I'm using SN65HVD230D and MCP2515 to create CANbus transmission. I'm working on 3.3V. I did loopback test on the master and slave - everything is OK. Problem comes when I try to send data. The sender blocks after a few sends and the receiver doesn't receive anything.
Here are samples of my code:
SENDER:
Code: |
#include <18F66J60.h>
#Fuses HS,NOWDT
#use delay(clock=25M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define EXT_CAN_CS PIN_B0
#define EXT_CAN_SI PIN_C4
#define EXT_CAN_SO PIN_C5
#define EXT_CAN_SCK PIN_C3
#include <can-mcp251x.c>
void main(void)
{
int32 can_id;
int can_data[8];
int can_length, counter,value;
struct rx_stat rxstat;
can_init();
can_set_mode(CAN_OP_NORMAL);
can_data[0] = 10;
can_data[1] = 20;
can_data[2] = 30;
can_data[3] = 40;
can_id=15;
while(1)
{
if ( can_tbe())
{
can_putd(can_id, can_data, 4, 3, TRUE, FALSE);
}
}
}
|
RECEIVER:
Code: |
#include <18F86J65.h>
#Fuses HS,NOWDT
#use delay(clock=25M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define EXT_CAN_CS PIN_C2
#define EXT_CAN_SI PIN_C4
#define EXT_CAN_SO PIN_C5
#define EXT_CAN_SCK PIN_C3
#include <can-mcp251x.c>
void main(void)
{
int32 can_id;
int can_data[8];
int can_length, counter,value;
struct rx_stat rxstat;
can_init();
can_set_mode(CAN_OP_NORMAL);
while(1)
{
if ( can_kbhit() ) //if data is waiting in buffer...
{
can_getd(can_id, &can_data[0], can_length, rxstat);
}
}
}
|
Can you tell me what's going on here?
Thanks! |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Mon Jun 15, 2015 9:00 am |
|
|
The transmitter is behaving as if there are no CAN nodes to acknowledge messages. It is trying to resend the first message over and over. The second and third message are buffered in the hardware, but they don't get sent as the first one has still not been acknowledged, and then the firmware locks as there are no spare transmit buffers.
The trouble is that with your code tightly looping round over and over, it's not going to be easy to tell if the transmitter is resending over and over, or your code is sending the same message over and over. It will look almost the same, varying only in timing, and then not by much.
Do you have an oscilloscope to look at the waveforms on the CAN L and CAN H lines? Do you have terminating resistors (typically 120R) at the ends of the bus? Can you receive anything using a CAN bus monitor?
How are you clocking the MCP2515s? I've not used the external ICs, but I believe they will work at up to 25MHz, and may be used to provide external clock for a processor, or from the processor's clock, with suitable wiring. I'm assuming you've got both the PIC and the 2515 to the same clock source. As far as I can see, all the bits should work at 25MHz at 3.3V, so that's good.
Sorry not to be much more help. Unfortunately, you haven't given us a lot to go on. |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Mon Jun 15, 2015 11:23 am |
|
|
Here is my schematic Click.
I supposed the same - I have no connection between the nodes, so I'll check the connections again. I have jumpers on the termination resistors, but both are in place.
Any other advices?
Thanks! |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|