CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

CAN bus transmission problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

CAN bus transmission problem
PostPosted: Tue Aug 12, 2014 2:03 am     Reply with quote

Greetings! I'm using 2 PIC18F2550 with MCP2515 and MCP2551. I have MPLab v8.91 and CCS v4.134.
Here are my programs:
SPI:
Code:

      #define EXT_CAN_CS   PIN_B4
      #define EXT_CAN_SI   PIN_B0
      #define EXT_CAN_SO   PIN_C7
      #define EXT_CAN_SCK  PIN_B1


Transmitter:
Code:

#include <18F2550.h>
#FUSES HS,NOWDT,CPUDIV1
#use delay(clock=10M)

#include <can-mcp2515.c>

int status;
void main()
{
   int32 tx_id=24;
   int tx_pri=3;
   int1 tx_ext=0;
   int1 tx_rtr=1;
   output_high(PIN_B5);
   delay_ms(100);
   can_init();
   while(1)
   {
      
      if(can_tbe())
      {
         status=can_putd(tx_id,5,1,tx_pri,tx_ext,tx_rtr);
      }
      delay_ms(10);
      
   }
}


Receiver:
Code:

#include <18F2550.h>
#FUSES HS,NOWDT,CPUDIV1
#use delay(clock=10M)

#include <can-mcp2515.c>
int dataHolder[10];
void main()
{
   int32 rx_id;
   int rx_len;
   struct rx_stat rxstat;
   output_high(PIN_B5);
   delay_ms(100);
   can_init();
   
   while(1)
   {
      if(can_kbhit())
      {
         if(can_getd(rx_id,&dataHolder[0],rx_len,rxstat))
         {
            delay_ms(1);
         }
      }
   }
}


I don`t receive anything on the receiver. I even don't pass the can_kbhit().
Is there any problem with my programs?!
Thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 12, 2014 6:19 pm     Reply with quote

This thread has a link to a 2-board CAN bus test program.
http://www.ccsinfo.com/forum/viewtopic.php?t=39809
There is also sample code for a loopback test for mcp2515.

It's helpful to test the mcp2515 in loopback mode first, so you can prove
that your SPI communication is working correctly. Then do the 2-board
test to prove that two CAN bus boards can talk to each other.
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Sat Aug 16, 2014 11:34 pm     Reply with quote

OK! I ran the loop back test and it`s OK, but it doesn`t transmit on line.
Here you can see my schematic
I have pull up resistors on SPI pins, too. Reset pin is high!
Are there any errors?!
Thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Aug 17, 2014 12:32 am     Reply with quote

Quote:
but it doesn`t transmit on line.

How are you testing this ? Are you using your programs that you posted
earlier in this thread ? Or are you using my 2-board test program here:
http://www.ccsinfo.com/forum/viewtopic.php?t=29627&start=7

Also, on your schematic, you have the SDO and SDI pins swapped.
But it doesn't matter because the mcp-251x.c driver uses software SPI
by default. In earlier compiler versions, it only use software SPI.
So you're OK with those connections. It just wouldn't work with
hardware SPI. You don't need to change it right now.
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Sun Aug 17, 2014 12:32 am     Reply with quote

I have not read your datasheet, but normally SI would go to SO on a slave master config. What normally helps me i to define the pins as MOSI for master or MISO for the slave.

Regards
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Sun Aug 17, 2014 6:15 am     Reply with quote

If this is true, why I have response in the loop back test?!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Aug 17, 2014 10:52 am     Reply with quote

Stoyanoff,
I told you in my earlier post:

Quote:

Also, on your schematic, you have the SDO and SDI pins swapped.
But it doesn't matter because the mcp-251x.c driver uses software SPI
by default
. In earlier compiler versions, it only use software SPI.
So you're OK with those connections. It just wouldn't work with
hardware SPI. You don't need to change it right now
.


And you didn't answer my question
Quote:
How are you testing this ? Are you using your programs that you posted
earlier in this thread ? Or are you using my 2-board test program here:

So I don't want to continue this.
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Sun Aug 17, 2014 10:36 pm     Reply with quote

Sorry! My fault! I`m using the programs from the link you gave me.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 18, 2014 1:08 am     Reply with quote

OK, each MCP2515 must connected to a MCP2551 transceiver chip.
Then the two MCP2551 chips must be connected to each other.
It has to look similar to this schematic, except that instead of ATMega
chips, you have 18F2550 PICs:
http://www.bobandeileen.com/wp-content/uploads/2007/08/schematic.JPG

An RS232 cable must be connected between the 1st board and your PC.
Code:
    rs232          CAN
PC <-----> Board1 <---> Board2


Quote:
but it doesn`t transmit on line.

If it doesn't transmit, then tell us how you know this. Are you looking
at CANH and CANL with an oscilloscope ? Tell us, in detail, how you
know it doesn't work.
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Fri Aug 22, 2014 3:35 am     Reply with quote

Thanks, a lot! I fixed it! I had a bad connection on the one MCP2551.
Just for the record connections are:
controller <-> MCP2515
SI - SI
SO - SO
as PCM programmer`s schematic!
I there any chance to use another source for MCP2515 oscillator. For example to use one of the PWM exits of PIC18F2550 or RC group?!
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Fri Aug 22, 2014 3:42 am     Reply with quote

The easiest thing, is to use an external oscillator module, at 8MHz, and run both the PIC, and the MCP from this. Smile

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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