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

Problem with MCP2515 and PIC18F86J65

 
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

Problem with MCP2515 and PIC18F86J65
PostPosted: Wed Jul 08, 2015 11:12 am     Reply with quote

Greetings! I've connected MCP2515 to PIC18F86J65:
MCP2515 CLK -> PIC18F86J65 CLK
SI->SO
SO->SI
Here comes the problem. When I use this spi configuration:
Code:

#define EXT_CAN_CS   PIN_C2
#define EXT_CAN_SI   PIN_C4
#define EXT_CAN_SO   PIN_C5
#define EXT_CAN_SCK  PIN_C3
#use spi(MASTER,MODE=0,DI=EXT_CAN_SO,DO=EXT_CAN_SI,CLK=EXT_CAN_SCK,bits=8,stream=MCP2510)

everything works fine!
If I change the pins as they should be (PIN_C4 is SDI and PIN_C5 is SDO) it doesn't work and blocks on the #use spi row.
What's going on here?
Thanks!

PP: Now I`m seeing I`ve put 25MHz quartz, but the MCP2515 max speed is 10MHz. May be this is the problem. Is there any problem if I put 10MHz to the driver and 25MHz to the controller?! I`ll decrease the spi baud rate!
Ttelmah



Joined: 11 Mar 2010
Posts: 19557

View user's profile Send private message

PostPosted: Wed Jul 08, 2015 3:09 pm     Reply with quote

Lets get this clear. When you switch configuration, you switch the wires as well?.

If so, then speed could be a problem. When you switch to the alternative configuration, you are using software SPI. This runs typically at least 20* slower than the hardware is capable of going. However the hardware SPI can be turned down. The speed you can run the SPI bus at, is dependant on the capacitances you have on your connections, the tendency to ringing etc.. not just the abilities of the chips. The clock speeds of the two devices can be anything you want (suitably supported), it is the interface timing you have to get right.

The 86J at 25MHz, will only be clocking the SPI at 6.25MHz (Fosc/4 is normally the maximum for SPI). The connection should work fine at this, but it suggests you may have a signalling issue at the high rate. You may need to terminate the signal wires at their receive ends to avoid ringing.

Try turning the rate down 1.5625MHz. If this works, and is adequate, 'smile' otherwise you are going to need to look at the actual lines and how they are laid out.
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Thu Jul 09, 2015 1:37 am     Reply with quote

No, may be this is the problem. I assumed MCP2515 has software SPI too. It seems it doesn`t. So I need to change the wires and the pin configuration simultaneously.
Thanks!
Ttelmah



Joined: 11 Mar 2010
Posts: 19557

View user's profile Send private message

PostPosted: Thu Jul 09, 2015 2:40 am     Reply with quote

If you are not swapping the pins, then it says you have a wiring error.

Slaves can't do 'software' SPI (well they can, but only with processors running hundreds of times faster than the SPI rate). So if it is working with the pins reversed, it means you have got the pins reversed somewhere between the chips...

Bus it through with a meter. SDO on the 86J is pin 46 (TQFP package), Then again depending on the package SDI on the 2515, is pin 16 (TSSOP package). Check the connection pin by pin.
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

Re: Problem with MCP2515 and PIC18F86J65
PostPosted: Thu Jul 09, 2015 3:19 am     Reply with quote

SDO on the master doesn't go to SDO on the slave, and SDI doesn't go to SDI! SDO (Serial Data Out) on the slave goes to SDI (Serial Data In) on the master and vice-versa.

There is no standard for SPI, and there are several alternative names for the signals. I prefer the arguably some what clunkier MISO and MOSI - Master In Slave Out and Master Out Slave In - labels as its a bit clearer as to how to wire them.

I2C is a bit easier in this respect as the labels for the data lines are standardised and the same for all parts.

The MCP2515 will clock up to 40MHz at 5V and 25MHz at 3.3V. The CCS driver assumes its running off a 20MHz clock, so it'll work well above 10MHz. The SPI on the MCP2515 can only run to 10MHz, but that's different from its clock rate. Personally, I'd probably want to run both the PIC and the MCP2515 from the same clock, probably 10, 16 or 20MHz, generated in the PIC from a crystal.
Ttelmah



Joined: 11 Mar 2010
Posts: 19557

View user's profile Send private message

PostPosted: Thu Jul 09, 2015 3:52 am     Reply with quote

He actually says that in his first post!.
However it sounds as if it has gone wrong somewhere....

On the clocks, I'd slightly 'differ'. Prefer to use an external oscillator _module_ and run everything off this. Don't like tapping extra lines off the PIC oscillator, always tends to result in slight frequency errors.
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Sat Jul 11, 2015 12:42 am     Reply with quote

OK! I fixed this. There is a new problem. I've tried to use CAN bus with TCPIP stack. It seems the CCS TCPIP stack v2011-01-26 prevents the usage of SPI interface. How is that possible and how to override it? I couldn't find in the stack files other #use spi definition.
Help, please!
Ttelmah



Joined: 11 Mar 2010
Posts: 19557

View user's profile Send private message

PostPosted: Sat Jul 11, 2015 7:20 am     Reply with quote

There should be SPI configurations there, but only used if you have selected one of the SPI interfaced modes. They should be there though....

Step back and do a really basic test. Forget about the chip you are actually driving, and configure SPI to some default slow speed, and just have it outputting single bytes at different points scattered through the program. See if it does output them (scope), and if you make the byte values different, then you should be able to which values it outputs, and where these stop.
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