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

MCP2515 PICtail Plus Daughter Board with Explorer 16

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



Joined: 09 Sep 2009
Posts: 2

View user's profile Send private message

MCP2515 PICtail Plus Daughter Board with Explorer 16
PostPosted: Wed Sep 09, 2009 3:40 am     Reply with quote

Hello,

I have a problem with setting up a communication with the MCP2515. For testing I use the source-code from the file can-mcp251xx.c.

The hardware SPI pins are set with the following code.

Code:
#ifndef EXT_CAN_CS
   #define EXT_CAN_CS    PIN_B5
   #define EXT_CAN_SI     PIN_F8
   #define EXT_CAN_SO    PIN_F7
   #define EXT_CAN_SCK  PIN_F6


The problem is when the function can_set_mode is called there is no result (no communication?). It is hanging in the while-loop.

Code:
void can_set_mode(CAN_OP_MODE mode) {
   struct struct_CANCTRL old_CANCTRL;

   old_CANCTRL=mcp2510_read(CANCTRL);

   old_CANCTRL.reqop=mode;

   mcp2510_write(CANCTRL, (int)old_CANCTRL);

   do {
      old_CANCTRL=mcp2510_read(CANCTRL);
   } while (old_CANCTRL.reqop != mode);
}

Code:
int mcp2510_read(int address) {
   int command[2];
   int i;
   int data;

   command[1]=0x03;
   command[0]=address;

   output_low(EXT_CAN_CS);

   for (i=0;i<16;i++) {
      output_bit(EXT_CAN_SI, shift_left(&command[0],2,0));
      output_high(EXT_CAN_SCK);
      output_low(EXT_CAN_SCK);
   }
   for (i=0;i<8;i++) {
      shift_left(&data,1,input(EXT_CAN_SO));
      output_high(EXT_CAN_SCK);
      output_low(EXT_CAN_SCK);
   }

   output_high(EXT_CAN_CS);

   return(data);
}

Code:
void mcp2510_write(int address, int data) {
   int command[3];
   int i;

   command[2]=0x02;
   command[1]=address;
   command[0]=data;

   output_low(EXT_CAN_CS);

   for (i=0;i<24;i++) {
      output_bit(EXT_CAN_SI, shift_left(&command[0],3,0));
      output_high(EXT_CAN_SCK);
      output_low(EXT_CAN_SCK);
   }

   output_high(EXT_CAN_CS);
}


Any help or insides would be greatly appreciated.

Regards,

Martin Land.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 09, 2009 1:24 pm     Reply with quote

What PIC are you using on the Explorer16 ?

What is your CCS compiler version ?
Martin Land



Joined: 09 Sep 2009
Posts: 2

View user's profile Send private message

PostPosted: Thu Sep 10, 2009 1:10 am     Reply with quote

Hello.

I am using the PIC24FJ128GA010 with a PCD compiler, version 4.093.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Sep 10, 2009 1:29 pm     Reply with quote

I think the problem may be caused by the different size of the 'int'
data type in PCD, compared to PCM or PCH.

In PCD, an 'int' is a signed 16-bit integer. (i.e., ANSII compatible)
But in PCM or PCH, an 'int' is an unsigned 8-bit integer.

The mcp-251x.c driver is written for PCM or PCH. This is going to cause
problems. For example, the shift_left() routine operates on bytes.
In mcp2510_read(), the command[] array is assumed to be an array of
bytes. But in PCD, it becomes an array of signed 16-bit integers.
The shift_left() routine won't work correctly now.

I don't own the PCD compiler. Maybe someone who has it can tell you
how to make it be compatible with the CCS drivers. Maybe there is a
quick fix.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Sep 11, 2009 8:19 am     Reply with quote

I do --- but I think you can typedef the int's into int8's if the rest of your code is int8 happy...

I'd have to look more closely later tomorrow...

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
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