|
|
View previous topic :: View next topic |
Author |
Message |
1980best
Joined: 25 May 2007 Posts: 26
|
I want to work with mcp2515 |
Posted: Fri Oct 11, 2013 2:01 am |
|
|
Code: |
#include <18F4550.h>
#device adc=8
#use delay(clock=20000000)
//#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#fuses HS,NOWDT,NOPROTECT,NOLVP,PUT,noMCLR
#BYTE PORTA = 0xF80
#BYTE PORTB = 0xF81
#BYTE PORTC = 0xF82
#BYTE PORTD = 0xF83
#BYTE PORTE = 0xF84
#BYTE TRISA = 0xF92
#BYTE TRISB = 0xF93
#BYTE TRISC = 0xF94
#BYTE TRISD = 0xF95
#BYTE TRISE = 0xF96
#define BOARD2_ID 25
char data[8];
unsigned char len;
unsigned char stat;
int32 rx_id;
int32 tx_id;
int8 rx_len;
int8 buffer[8];
#define CAN_USE_EXTENDED_ID TRUE
#define CAN_BRG_SEG_2_PHASE_TS TRUE
#define CAN_BRG_PRESCALAR 4
#define CAN_BRG_SYNCH_JUMP_WIDTH 0
#define CAN_BRG_PROPAGATION_TIME 2
#define CAN_BRG_PHASE_SEGMENT_1 5
#define CAN_BRG_PHASE_SEGMENT_2 5
#define CAN_BRG_WAKE_FILTER TRUE
#define CAN_BRG_SAM FALSE
#include "can-mcp2515.c"
#USE SPI (MASTER, CLK=PIN_B1, DI=PIN_C7, DO=PIN_B0, MODE=0, BITS=8, STREAM=SPI_1)
void main()
{
can_init();
can_putd(tx_id,data,8,3,TRUE,FALSE);
can_getd(rx_id,data,len,stat);
//Example blinking LED program
while(true)
{
output_low(PIN_E0 );
delay_ms(100);
output_high(PIN_E0 );
delay_ms(100);
output_low(PIN_D1 );
delay_ms(100);
output_high(PIN_D1 );
delay_ms(100);
}
}
|
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en537141
Code: |
#include <can-mcp251x.h>
//IO pins connected to MCP2510ca
#ifndef EXT_CAN_CS
#if defined(__PCD__)
#define EXT_CAN_CS PIN_B4
#define EXT_CAN_SI PIN_B0
#define EXT_CAN_SO PIN_C7
#define EXT_CAN_SCK PIN_B1
|
???
program stopped this here
Code: |
void can_set_mode(CAN_OP_MODE mode) {
struct struct_CANCTRL old_CANCTRL;
memset(&old_CANCTRL,mcp2510_read(CANCTRL),1);
// old_CANCTRL=mcp2510_read(CANCTRL);
old_CANCTRL.reqop=mode;
mcp2510_write(CANCTRL, (unsigned int8)old_CANCTRL);
do {
memset(&old_CANCTRL,mcp2510_read(CANCTRL),1);
//old_CANCTRL=mcp2510_read(CANCTRL);
}
while (old_CANCTRL.reqop != mode);
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Oct 14, 2013 6:29 pm |
|
|
I think you have incorrectly swapped the pin assignments shown below.
Quote: | #define EXT_CAN_CS PIN_B4
#define EXT_CAN_SI PIN_B0
#define EXT_CAN_SO PIN_C7
#define EXT_CAN_SCK PIN_B1
|
I think it should be like this:
Code: | #define EXT_CAN_CS PIN_B4
#define EXT_CAN_SI PIN_C7
#define EXT_CAN_SO PIN_B0
#define EXT_CAN_SCK PIN_B1
|
Here is my reasoning:
The schematic of your board (on page 20) shows the SDO pin of the
PIC is on pin C7:
http://ww1.microchip.com/downloads/en/DeviceDoc/51757a.pdf
The mcp-251x.c driver has these pin assigments for SPI:
Quote: |
#use spi(MASTER,MODE=0, DI=EXT_CAN_SO, DO=EXT_CAN_SI, CLK=EXT_CAN_SCK, bits=8, stream=MCP2510)
|
That means that EXT_CAN_SI must be defined as PIN_C7. And then
the other pin, EXT_CAN_SO must there be defined for PIN_B0.
Try the 2nd set of pin #defines above and see what happens. |
|
|
1980best
Joined: 25 May 2007 Posts: 26
|
|
Posted: Sat Oct 26, 2013 5:54 pm |
|
|
which one true ?
ccs wizard make data in mirror !!!
you will wizard see please |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Sun Oct 27, 2013 1:25 am |
|
|
I don't think you will find that most programmers here use the Wizard.....
However the Wizard does not select these pins. You do, _in_ the Wizard.
The Wizard has a lot of faults (the settings to disable SPI have been wrong for many years), and in many places it makes the wrong decisions (defaulting to not enabling ERRORS when hardware RS232 is selected for example).
Don't rely on, or trust the Wizard. Do some research and work the settings out yourself. |
|
|
|
|
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
|