|
|
View previous topic :: View next topic |
Author |
Message |
kedale
Joined: 19 Jul 2006 Posts: 5
|
MCP2515 + 16f628 communication problems |
Posted: Wed Jul 19, 2006 10:41 am |
|
|
Hi everybody,
I try to make a CAN network but i'm simply stopped at initialization due to communication problems between a MCP2515 and a 16f628.
My 16f628 works with a 8Mhz quartz.
The CS/ Pin of the MCP2515 is linked with A0 of 16f628
The S0 Pin of the MCP2515 is linked with A1of 16f628
The SI Pin of the MCP2515 is linked with A2 of 16f628
The SCK Pin of the MCP2515 is linked with A3 of 16f628
so, at the beginning of my mcp2510.c, i have :
//IO pins connected to MCP2510
#ifndef EXT_CAN_CS
#define EXT_CAN_CS PIN_A0
#define EXT_CAN_SI PIN_A2
#define EXT_CAN_SO PIN_A1
#define EXT_CAN_SCK PIN_A3
#define EXT_CAN_INT PIN_B0
#define EXT_CAN_RX0BF PIN_B1
#define EXT_CAN_RX1BF PIN_B2
#define EXT_CAN_TX2RTS PIN_B3
#define EXT_CAN_TX1RTS PIN_B4
#define EXT_CAN_TX0RTS PIN_B5
#endif
And i've simplified my program of the 16f628 to the maximum, to have:
#include <16F628A>
#use delay(clock=8000000)
#fuses HS,NOPROTECT,NOLVP,NOWDT,NOBROWNOUT
#define GREEN_LED PIN_B4
#include "includes/canMCP2515.c"
void main() {
SETUP_CCP1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);
setup_vref(VREF_HIGH);
// On programme les registres du MCP2515
can_init();
}
In fact, in the can_init() function, i have written:
mcp2510_init();
can_set_mode(CAN_OP_CONFIG); //must be in config mode before params can be set
output_high(GREEN_LED);
delay_ms(100);
while((CANSTAT&0xE0) != 0x80){can_set_mode(CAN_OP_CONFIG);}
output_low(GREEN_LED);
can_set_baud();
, in order to detect(with the LEDs) if I can pass through this line, but I can't, so I have deduced that the problem was the communication!
Thank you for your help.
Matthieu |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jul 19, 2006 3:54 pm |
|
|
Do a test to see if you can read and write from the chip.
The CANINTE register is R/W on all bits, so you can use it to test
if you can talk to the chip.
Do you have the \RESET pin on the mcp2515 connected to anything ?
Is it connected to a system reset signal on your board ? If not,
for this test, connect it to a PIC pin, and set it low for 10 usec, then
set it high. This will do a hardware reset of the chip. You'll have
to add that code to the program below.
I don't have a mcp2515 chip, so I haven't tested the following code,
but it should probably work.
Code: |
#include <16F877.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
// Override the default pins used in the CCS driver
// by specifying our pins here.
#define EXT_CAN_CS PIN_A0
#define EXT_CAN_SI PIN_A2
#define EXT_CAN_SO PIN_A1
#define EXT_CAN_SCK PIN_A3
#include <can-mcp2510.c>
//=================================
main()
{
int8 result;
//can_init();
output_high(EXT_CAN_CS);
output_low(EXT_CAN_SCK);
// Write 0x55 to the CANINTE register and see if we
// can read it back.
mcp2510_write(CANINTE, 0x55);
result = mcp2510_read(CANINTE);
printf("Wrote 0x55, Read %X \n\r", result);
// Now write 0xAA to the CANINTE register and see if we
// can read it back.
mcp2510_write(CANINTE, 0xAA);
result = mcp2510_read(CANINTE);
printf("Wrote 0xAA, Read %X \n\r", result);
while(1);
} |
|
|
|
kedale
Joined: 19 Jul 2006 Posts: 5
|
|
Posted: Thu Jul 20, 2006 6:26 am |
|
|
Thank you for all, helped by your code source, I discovered that in fact i didn't read CANSTAT, so it couldn't change anymore!
So in fact, now, everything's fine, thank you thank you!! |
|
|
|
|
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
|