• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Problem with Interfacing MCP2515 CAN Controller and PIC18F4520

Naren Rover

New Member
Hi, guys I'm working with MCP2515 CAN Module and PIC18F series.I write a single byte data and read it back using SPI Protocol.
But I am unable to receive any data back.
here i have posted the code please check it and help me.
i connected two MCP2525 modules , so I think there is no problem with Hardware
( 1 from local vendor and other from Ali express).
I don't have any oscilloscope
Thank you.
 

Attachments

Naren Rover

New Member
Actually , No i'm using 1 module only, I had another one lying around , so i removed this one and hooked that one up just to make sure if IC was damaged, but i did not get anything from that also.
1 MCP2515 connected with PIC18F to send a CAN Message which will be received by PEAK CAN and will be displayed in Monitor.
I'm in initial step of development , trying to" communicate with MCP2515 and PIC18F" , which i'm not successful.
I'm at it for 2 days and it's really frustrating.
Thank you.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
Okay!! I think you should read up on canbus! Its not like simple SPI, it works with frames... You cannot just send a byte.. You need to think of it like a letter... You won't get a response if there is no address on the front... Check canbus on wiki.. If it were pic to pic then you could possible do without a protocol but peak can will require a frame...( I think there are led indicators to show activity, but that's about it ).
 

Naren Rover

New Member
Okay!! I think you should read up on canbus! Its not like simple SPI, it works with frames... You cannot just send a byte.. You need to think of it like a letter... You won't get a response if there is no address on the front... Check canbus on wiki.. If it were pic to pic then you could possible do without a protocol but peak can will require a frame...( I think there are led indicators to show activity, but that's about it ).
I think my question was misunderstood.
I have not yet started CAN programming
All i'm trying to is , communicating between PIC and MCP
i write a register in MCP using SPI protocol and Reading it back to see if the communication is successful
Im not getting anything from MCP . All Im getting is 0x00.
I need you guys to see if my program is correct or did i make any mistakes
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
I don't think you can. The byte will be sent to a tx register buffer and isn't available to be read back.. Use my original misunderstanding.. use both MCP chips and send and receive that way... Like we do for rs232 testing...
 

Naren Rover

New Member
i have attached the MCP 2515 data sheet. I'm not talking about CAN transmit - receive message.
All I'm trying to do is to check if there is a communication between MCP and my PIC board that's all
There is register called CAN Control register(as shown in the uploaded .jpg file) , which is to written by the PIC controller to set it in different modes.
CAN Control register is READ/WRITE Register. with address 0x0F
I'm writing 0x80 to the register setting it in "Configuration mode ".
and reading it back from CAN_Status_Reg , which has address 0x0E
to see if my command was recieved from PIC.
but I'm getting 0x00;

i don't know if the problem is in my coding or someother thing.
that's why i need you guys to help me
 

Attachments

Naren Rover

New Member
Do you have the SPI configured correctly?, is it set to the correct type of SPI?.
Thanks guys i found the mistake, it was with SPI mode selection. i data sheet it was said Mode 0,0 , so i thought Clock phase and polarity to be Zero, which was not like that when i read the data sheet again.
Now i'm able to read and write it back.

if possible I'll upload a Basic transmit receive code for MPC2515 in C language.
Thank you
 

dr pepper

Well-Known Member
Most Helpful Member
I had an issue trying to get a mcp25xx module to work too, I was using a non standard bitrate because the deafult xtal frequency in the lib I was using wasnt the xtal freq in my modules.
 

Latest threads

EE World Online Articles

Loading

 
Top