|
|
View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 17, 2010 4:14 pm |
|
|
I have a 3M breadboard with a 16F690 already on it. I added a MCP2510
chip and jumpered it so it would similar to your board. I have a Max232A
on my breadboard, so I used the hardware UART pins on the 16F690.
I'm using a 20 MHz crystal on the MCP2510, with 22 pf caps to ground
on each side of the crystal. I have the \Reset pin on the MCP2510
connected to a 10K pull-up resistor. The can-mcp2510.c driver does
a software controlled reset of the MCP2510, so the hardware \Reset
pin is not used (it's pulled up to +5v).
The Loopback test code shown below works. It displays the following in
a terminal window on the PC:
Quote: |
Starting
Tx OK, Rx OK, Rx data = 55
Tx OK, Rx OK, Rx data = 55
Tx OK, Rx OK, Rx data = 55
Tx OK, Rx OK, Rx data = 55
Tx OK, Rx OK, Rx data = 55
Tx OK, Rx OK, Rx data = 55
Tx OK, Rx OK, Rx data = 55
Tx OK, Rx OK, Rx data = 55
Tx OK, Rx OK, Rx data = 55
Tx OK, Rx OK, Rx data = 55
Tx OK, Rx OK, Rx data = 55
Tx OK, Rx OK, Rx data = 55
Tx OK, Rx OK, Rx data = 55
Tx OK, Rx OK, Rx data = 55
Tx OK, Rx OK, Rx data = 55
|
Code: |
#include <16F690.h>
#fuses INTRC_IO,NOWDT,BROWNOUT,PUT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B7, rcv=PIN_B5, ERRORS)
//#use rs232(baud=9600, xmit=PIN_C4, rcv=PIN_C5, INVERT)
#define EXT_CAN_CS PIN_C6
#define EXT_CAN_SI PIN_C7
#define EXT_CAN_SO PIN_B4
#define EXT_CAN_SCK PIN_B6
#include <can-mcp2510.c>
//=================================
void main(void)
{
int32 can_id;
int8 can_data[8];
int8 can_length;
struct rx_stat rxstat;
can_init();
can_set_mode(CAN_OP_LOOPBACK);
printf("Starting\n\r");
can_data[0] = 0x55;
while(1)
{
if(can_putd(42, can_data, 1, 3, TRUE, FALSE))
printf("Tx OK, ");
else
printf("Tx failed, ");
while(!can_kbhit());
if(can_getd(can_id, &can_data[0], can_length, rxstat))
printf("Rx OK, ");
else
printf("Rx failed, ");
printf("Rx data = %x \n\r", can_data[0]);
delay_ms(500);
}
}
|
This was tested with compiler vs. 4.104. |
|
|
Benzino
Joined: 15 Feb 2010 Posts: 24
|
|
Posted: Thu Feb 18, 2010 8:06 am |
|
|
Hi,
PCM programmer wrote: | What do you have connected to the \Reset pin and the OSC1 and OSC2
pins on the MCP2515 ? |
I have my \Reset pin series with 10kohm resistor and connected to +5 V.
The OSC1 and OSC2 are connected to 16MHz crystal with two .1 uF capacitor grounded on each side of the crystal.
I am actually using the MCP2515 PICtail Demo Board from Microchip and program the 16F676 with a blank code for the MCP2515 and MCP2551.
For PIC 16F690 I use the Low Pin Count Board from PICKit 2 and wire selected pin to the PICtail Demo board.
The reason I have to do this is because this is all I was given to work with.
One question about the CAN baud rate on your code. Which baud rate that you're using?
My CCS compiler version is 4.093. I will try out your code and see if it works. |
|
|
Ttelmah Guest
|
|
Posted: Thu Feb 18, 2010 8:16 am |
|
|
Benzino wrote: | Hi,
PCM programmer wrote: | What do you have connected to the \Reset pin and the OSC1 and OSC2
pins on the MCP2515 ? |
I have my \Reset pin series with 10kohm resistor and connected to +5 V.
The OSC1 and OSC2 are connected to 16MHz crystal with two .1 uF capacitor grounded on each side of the crystal.
I am actually using the MCP2515 PICtail Demo Board from Microchip and program the 16F676 with a blank code for the MCP2515 and MCP2551.
For PIC 16F690 I use the Low Pin Count Board from PICKit 2 and wire selected pin to the PICtail Demo board.
The reason I have to do this is because this is all I was given to work with.
One question about the CAN baud rate on your code. Which baud rate that you're using?
My CCS compiler version is 4.093. I will try out your code and see if it works. |
Aaargh......
You want capacitors like 0.1uF, on the _supply_, _not_ the crystal.
The normal loading capacitance for a crystal, is in the order of perhaps 20pF. 0.1uF, will stop it running.....
Best Wishes |
|
|
Benzino
Joined: 15 Feb 2010 Posts: 24
|
|
Posted: Thu Feb 18, 2010 8:23 am |
|
|
Ttelmah wrote: | Benzino wrote: | Hi,
PCM programmer wrote: | What do you have connected to the \Reset pin and the OSC1 and OSC2
pins on the MCP2515 ? |
I have my \Reset pin series with 10kohm resistor and connected to +5 V.
The OSC1 and OSC2 are connected to 16MHz crystal with two .1 uF capacitor grounded on each side of the crystal.
I am actually using the MCP2515 PICtail Demo Board from Microchip and program the 16F676 with a blank code for the MCP2515 and MCP2551.
For PIC 16F690 I use the Low Pin Count Board from PICKit 2 and wire selected pin to the PICtail Demo board.
The reason I have to do this is because this is all I was given to work with.
One question about the CAN baud rate on your code. Which baud rate that you're using?
My CCS compiler version is 4.093. I will try out your code and see if it works. |
Aaargh......
You want capacitors like 0.1uF, on the _supply_, _not_ the crystal.
The normal loading capacitance for a crystal, is in the order of perhaps 20pF. 0.1uF, will stop it running.....
Best Wishes |
Thank you for your respond.
I looked into the datasheet again and I was wrong. The data sheet shows that there is two capacitors connected to the crystal and grounded on each side but it doesn't specifically say the parameter.
The .1uF was for other part of the schematic according to the PDF below
http://ww1.microchip.com/downloads/en/DeviceDoc/51572a.pdf |
|
|
Benzino
Joined: 15 Feb 2010 Posts: 24
|
|
Posted: Thu Feb 18, 2010 9:44 am |
|
|
Hi PCM programmer,
I tried your code with slightly changes so it produces the following data.
Code: |
Begin
Starting
Tx OK, Rx failed, Rx data = 55
Tx OK, Rx failed, Rx data = 55
Tx OK, Rx failed, Rx data = 55
Tx OK, Rx failed, Rx data = 55
Tx OK, Rx failed, Rx data = 55
...
|
and here is my PIC code
Code: |
#include <16F690.h>
#FUSES INTRC_IO,NOWDT,PUT,NOMCLR, BROWNOUT
#use delay(clock=4000000)
//#use rs232(baud=9600, xmit=PIN_B7, rcv=PIN_B5, ERRORS)
#use rs232(baud=9600, xmit=PIN_C4, rcv=PIN_C5, INVERT)
#define EXT_CAN_CS PIN_C6
#define EXT_CAN_SI PIN_C7
#define EXT_CAN_SO PIN_B4
#define EXT_CAN_SCK PIN_B6
#include <can-mcp2510.c>
//=================================
void main(void)
{
int32 can_id;
int8 can_data[8];
int8 can_length;
struct rx_stat rxstat;
printf("Begin\n\r");
can_init();
can_set_mode(CAN_OP_LOOPBACK);
printf("Starting\n\r");
can_data[0] = 0x55;
while(1)
{
if(can_putd(42, can_data, 1, 3, TRUE, FALSE))
printf("Tx OK, ");
else
printf("Tx failed, ");
while(!can_kbhit());
if(can_getd(can_id, &can_data[0], can_length, rxstat))
printf("Rx OK, ");
else
printf("Rx failed, ");
printf("Rx data = %x \n\r", can_data[0]);
delay_ms(500);
}
}
|
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().
Please advise, |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 18, 2010 11:52 am |
|
|
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
|
|
Posted: Thu Feb 18, 2010 12:29 pm |
|
|
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
|
|
Posted: Thu Feb 18, 2010 12:56 pm |
|
|
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
|
|
Posted: Mon Feb 22, 2010 9:28 am |
|
|
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 |
Posted: Fri Feb 26, 2010 9:37 am |
|
|
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
|
|
Posted: Fri Feb 26, 2010 9:48 am |
|
|
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.
Cheers, |
|
|
sumeshm.pnr123 Guest
|
|
Posted: Sat Feb 27, 2010 3:40 am |
|
|
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
|
|
Posted: Sun Feb 28, 2010 1:04 am |
|
|
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
|
|
Posted: Sun Feb 28, 2010 8:40 am |
|
|
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
|
|
Posted: Sun Feb 28, 2010 9:32 am |
|
|
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);
}
}
}
|
|
|
|
|
|
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
|