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

Has anyone use PIC16F690 with MCP2515?
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 18, 2010 11:52 am     Reply with quote

Quote:

I'm not sure if this has anything to do with the NOMCLR that I added.
If I don't have it then it would not go through can_init().

It probably means you're missing the MCLR pullup resistor.

I think this may be your first PIC project. It would have been better
to start with something simple, instead of a CAN bus project.


Quote:
The OSC1 and OSC2 are connected to 16MHz crystal

If you look closely at the enlarged photo of the CCS Can bus board,
it shows a 20 MHz crystal on the MCP2515.
http://www.ccsinfo.com/product_info.php?products_id=CANbuskit
So I used a 20 MHz crystal on my test with the MCP2510. I don't know
if it will work with a 16 MHz. I've never tried it.

I suspect that you also have some errors in your connections. For
example, you may be missing the ground connection between the
PIC and the MCP2515.
Benzino



Joined: 15 Feb 2010
Posts: 24

View user's profile Send private message

PostPosted: Thu Feb 18, 2010 12:29 pm     Reply with quote

Quote:
It probably means you're missing the MCLR pullup resistor.


I will add a pull-up resistor on the 16F690. Any specific value that you might suggest?

Quote:
I think this may be your first PIC project. It would have been better
to start with something simple, instead of a CAN bus project.


It is not my first PIC project but the one I did before were basic PIC programming using BASIC language which I have to setup all the TRIS, ANSEL, etc. individually.

So basically I don't have any experience writing PIC to use RS232 or CAN and never use CCS compiler or MPLAB.

But the task was assigned to me so I'm trying to work it out.
I would like to get the CCS CAN demo kit to help me understand things better but I cannot at the moment.


Quote:
I suspect that you also have some errors in your connections. For
example, you may be missing the ground connection between the
PIC and the MCP2515.

I did have the ground connection between the two board and they also use the same power (+5V)

I am just wondering what CAN baud rate might you be using in the previous example or even the CCS example?

Thank you
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 18, 2010 12:56 pm     Reply with quote

The MCLR pull-up resistor is recommended to be 10K ohms if you're
using a Microchip ICD2, or 47K ohms if you're using a CCS ICD.


I don't know what the CCS default baud rate is. They don't tell us.
I would have to look at the values in the can-mcp2510.h file and figure
it out. It's not important for a loopback test.

I just tested it with a 16 MHz crystal on the MCP2510. It still works.

I believe you have a hardware problem somewhere. You are missing
a connection, or have the wires crossed, or something. Perhaps you
are running the two boards at different voltages (+5v for one, and
+3.3v for the other). That could cause problems.
Benzino



Joined: 15 Feb 2010
Posts: 24

View user's profile Send private message

PostPosted: Mon Feb 22, 2010 9:28 am     Reply with quote

Hi,

I got the CCS CAN bus demo kit afterward so that I know that there is no problem with the hardware side before I implement the protocol to my own software and hardware.

I will let you know how it goes.
sumeshm.pnr123
Guest







not getting output using CAN
PostPosted: Fri Feb 26, 2010 9:37 am     Reply with quote

I'm currently doing CAN protocol implementation using mcp2515 and pic in ccs compiler. It is working fine in configuration mode.
But in normal mode I'm not getting output (cannot transmit data using bus). It always shows bus error (TXERR=1, transmit bus error). Can you anyone help me ?
What should I do to avoid this error??
Benzino



Joined: 15 Feb 2010
Posts: 24

View user's profile Send private message

PostPosted: Fri Feb 26, 2010 9:48 am     Reply with quote

Hi,

I'm not an expert here but you can post your code here and there will be someone to look at it e.g. PCM programmer. I will help if I know anything. Very Happy

Cheers,
sumeshm.pnr123
Guest







PostPosted: Sat Feb 27, 2010 3:40 am     Reply with quote

here is the code.....
Code:

#include<16f877a.h>
#use delay(clock=16000000)   //select clock to 16MHz
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C5,BITS=8) //set baud rate to 9600
#include <stdio.h>
#include "can-mcp2515.c"

#define ac   65  // AC

char a[]="SUMESH M";
int dlc=0;
int32 nod=1;
struct rx_stat stat;
char data_rx[8];

void main(void)
{
   int i;
   struct txbNctrl_struct b_TXB0CTRL;

   printf("started execution\n\r");

   setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_XMIT_L_TO_H);
   mcp2510_init();
   delay_ms(200);
   printf("can init successful\r\n");

   mcp2510_write(CANCTRL, 0x00);
   printf("status%X\n\r",mcp2510_status());
   delay_ms(200);

   b_TXB0CTRL=mcp2510_read(TXB0CTRL);
   printf("TXB0CTRL=%X\n\r",(int)b_TXB0CTRL);
   if(b_TXB0CTRL.txreq==0)
      printf("transmit buffer empty\n\r");
   else
      printf("transmit buffer full\n\r");

   for(i=0;i<4;i++)   {
      if(can_tbe()!=0)
      {
      printf("inside IF loop\n\r");
      while(can_putd(ac,a,8,3,1,0)!=1);
      printf("data output successful\r\n");
      }
   }

   printf("status%X\n\r",mcp2510_status());

   b_TXB0CTRL=mcp2510_read(TXB0CTRL);
   printf("TXB0CTRL=%X\n\r",(int)b_TXB0CTRL);

   if(b_TXB0CTRL.txreq!=0)
      printf("transmit buffer full\n\r");
   else printf("transmit buffer empty\n\r");   
      if(b_TXB0CTRL.txerr==1)
      printf("bus error\n\r");
   else   
   printf("no bus error\n\r");

   while();
}

it shows the output in hyperterminal.....
Quote:

started execution
can init successful
status00
TXB0CTRL=00
transmit buffer empty
inside IF loop
data output successful
inside IF loop
data output successful
inside IF loop
data output successful
status54
TXB0CTRL=1B
transmit buffer full
bus error
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 28, 2010 1:04 am     Reply with quote

Describe the test setup.

Is this test being done with real hardware or is this a Proteus project ?

Do you have only one CAN bus node, or two nodes ? Your first node
consists of a 16F877A and an MCP2515. If you have two nodes, describe
the 2nd node. Does it also have a PIC and an MCP2515 chip on it ?

Do your CAN bus nodes each have a CAN bus transceiver chip, such as
the MCP2551 ?

Do you have the required CAN bus terminator resistors installed ?

Etc. Give a complete description of your test environment.
sumeshm.pnr123
Guest







PostPosted: Sun Feb 28, 2010 8:40 am     Reply with quote

hai PCM programmer,

thanx for your kind attention,

I'm using two similar nodes. I'l explain the node..
node contains PIC16F877A, MCP2515, MCP2551.
16Mhz is used for PIC, 8Mhz is used for MCP2551.
each node is working perfectly on loopback mode.
the problem is in normal mode. In normal mode after putting data, it shows transmit bus error (TXERR=1).
I'm using CCS compiler.
I edited its can-mcp251x.c library file to direct SPI. SPI communication is working fine..
I think problem is in configuration of bus baud rate. also i'm not edited can_init() of can-mcp251x.c file.
I've used terminal resisters 110ohm(as i have no 120ohm, i used two 220ohm parallel).. I have used ethernet cable as bus.


I'm expecting your valuable suggestion,
thanx in advance.....
sumeshm.pnr123
Guest







PostPosted: Sun Feb 28, 2010 9:32 am     Reply with quote

Its great.......''

I solved the bus error by configuring CNF1, CNF2, CNF3 in my own way to get 125KHz with 8Mhz crystal.
I set one node to transmit continuously and other node to poll continuously for receive a message.
But one problem is that at receiver side not receive any message.
I'm totally worried about it.

Below I post program at receiver side.
Code:

void main(void)
{
int i;
struct txbNctrl_struct b_TXB0CTRL;

setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_XMIT_L_TO_H);
printf("started execution\n\r");

can_init1();
delay_ms(200);
printf("can init successful\r\n");

mcp2510_write(CANCTRL, 0x00);
printf("status%X\n\r",mcp2510_status());
delay_ms(200);

while(1)
  {
   if(can_kbhit()==TRUE)
     {
      printf("data received\n\r");
      printf("data is =");
      while(can_getd(nod,data_rx,dlc,stat)!=1);
      printf("%s\n\r",data_rx);
     }
  }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 28, 2010 1:25 pm     Reply with quote

I suspect the connections are incorrect. Post a schematic of your
connections between the two boards.

For example, this schematic uses AtMega as the processor, but it does
show the connections going to the MCP2515, and the MCP2551 and
the terminator resistors.
http://www.bobandeileen.com/wp-content/uploads/2007/08/schematic.JPG
sumeshmpnr



Joined: 26 Feb 2010
Posts: 1

View user's profile Send private message

PostPosted: Mon Mar 01, 2010 3:30 am     Reply with quote

I exactly following this circuit for MCP2551 and MCP2515.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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