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

CAN 18F2480 & MCP2551 Oscillator Problem
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 Aug 13, 2009 1:18 pm     Reply with quote

The CCS CAN bus development board uses the CLKOUT signal from the
MCP2510 to run the PIC at 2.5 MHz. You're running the PIC from a
16 MHz crystal. I looked at the can-mcp2510.c file, and I don't see
anything in there that would cause a problem by running the PIC at
16 MHz. But, there might be something I missed.

Because you have never used the MCP2510 chip before, it's possible that
there are other hardware connection problems, besides the one that I
already found. I would check the hardware very closely. Make sure
you are connecting to the correct pins.


Last edited by PCM programmer on Fri Aug 21, 2009 1:32 pm; edited 1 time in total
Mael



Joined: 12 Aug 2009
Posts: 15

View user's profile Send private message

PostPosted: Thu Aug 13, 2009 3:37 pm     Reply with quote

Thank you very much for your help. I go to make a new board but first I want to check if the hardware is correct, can you check that there is no errors in hardware configurator please?
Regards.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 14, 2009 6:07 pm     Reply with quote

Your schematic looks like it will work with these CCS driver and example files:
Quote:

can-mcp2510.c
Ex_can_ccs_b.c
Mael



Joined: 12 Aug 2009
Posts: 15

View user's profile Send private message

PostPosted: Fri Aug 21, 2009 12:53 pm     Reply with quote

Thank you very much, finally I made my own program and it works perfectly with a 16F876, anyway for the final project I will use a 18F2480 (I know 18F2840 don't need MCP2510, but my intention is to have 2 buses in the same mcu). I explain you:
- I made a very easy program that writes only an identifier and 1 byte of data every second always the same.
- I made the program for a 16F876 and it work nice.
- I made the same program, only changing pic by a 18F2480 and the MCP2510 communicates right, but the output can data is changing every time, never is the identifier and the data that I send from the 18F2480.
I have check the mcp-2510.c and mcp-2510.h but I can not see problems, it must work.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 21, 2009 1:15 pm     Reply with quote

What compiler version(s) are you using for the 16F876 and the 18F2480 ?

What PIC i/o pins did you use for the 16F876 and the 18F2480 ?

Are you using the same board for both these PICs ? Did you remove
the 16F876 from a 28-pin socket, and install the 18F2480 in its place ?
Mael



Joined: 12 Aug 2009
Posts: 15

View user's profile Send private message

PostPosted: Fri Aug 21, 2009 1:20 pm     Reply with quote

I'm using PCH 4.068 compiler version to program both pics.
I have one PCB with a socket to change the pic, I'm using the same pcb for both, and the pins are the same in both, extracted from can-mcp2510.c
Code:
   #define EXT_CAN_CS   PIN_B1
   #define EXT_CAN_SI   PIN_C1
   #define EXT_CAN_SO   PIN_C0
   #define EXT_CAN_SCK  PIN_C3

I can not understand, how using the same board, the same pins and the same library can happen this, the program is the same in all cases, I only change the device.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 21, 2009 1:37 pm     Reply with quote

Post the test program that you are using, which calls the can-mcp2510.c
functions, and which uses the 18F2480. Hopefully, this is a short program.
Mael



Joined: 12 Aug 2009
Posts: 15

View user's profile Send private message

PostPosted: Fri Aug 21, 2009 1:43 pm     Reply with quote

Here you have main.c
Code:
#include "main.h"
#include <can-mcp2510.c>

void main()
{
   int TX_BUFFER[8];
   int32 TX_ID=0x5C1;
   int1 RESULTADO_ENV=FALSE;

   TX_BUFFER[0]=0x00;
   TX_BUFFER[1]=0x01;
   TX_BUFFER[2]=0x02;
   TX_BUFFER[3]=0x2B;

   can_init();
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_vref(FALSE);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab

   // TODO: USER CODE!!
LOOP:
   RESULTADO_ENV=can_putd(TX_ID, &TX_BUFFER[1],1,1,FALSE,FALSE);
   delay_ms(100);
   goto LOOP;
}

and main.h
Code:
#include <18F2480.h>
#device ICD=TRUE
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES LVP                      //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES PBADEN                   //PORTB pins are configured as analog input channels on RESET
#FUSES BBSIZ2K                  //2K words Boot Block size
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(clock=2500000)



Last edited by Mael on Fri Aug 21, 2009 2:01 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 21, 2009 1:51 pm     Reply with quote

Quote:
#FUSES LVP
#FUSES PBADEN

You need to use the NOLVP fuse. With LVP, the PIC can lock up if the
PGM floats or goes to a high level. Also, it wouldn't hurt if you set
the NOPBADEN fuse.



Quote:

LOOP:
RESULTADO_ENV=can_putd(TX_ID, &TX_BUFFER[1],1,1,FALSE,FALSE);
delay_ms(100);
goto LOOP;

The proper (the C way) to do this would be to use a while() loop.
Code:
while(1)
{
   RESULTADO_ENV=can_putd(TX_ID, &TX_BUFFER[1],1,1,FALSE,FALSE);
   delay_ms(100);
}

You can do while(1) or while(TRUE). Using goto's is left over coding
practice from ASM. You're in C now.
Mael



Joined: 12 Aug 2009
Posts: 15

View user's profile Send private message

PostPosted: Fri Aug 21, 2009 2:03 pm     Reply with quote

Thank you for the advice. I made the changes in the fuses and I still have the same problem Confused
I'm thinking something. Can be this because in 18F2480 there's a different speed on port B? I go to try configuring the board to use the port A
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 21, 2009 2:26 pm     Reply with quote

Quote:
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_vref(FALSE);

The first thing I would do, is to simply the test program. Get rid of all
this stuff. It's not necessary.
Mael



Joined: 12 Aug 2009
Posts: 15

View user's profile Send private message

PostPosted: Fri Aug 21, 2009 2:28 pm     Reply with quote

Ok, done, but still the same problem.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 21, 2009 2:33 pm     Reply with quote

Quote:
Ok, done, but still the same problem.

How are you testing this program ? How do you decide if it's working
or not ? What is the test procedure ?
Mael



Joined: 12 Aug 2009
Posts: 15

View user's profile Send private message

PostPosted: Fri Aug 21, 2009 2:37 pm     Reply with quote

I have a can reader connected to my pc and I see directly all the messages (www.canusb.com).
I'm sure that this works, I've read perfectly all messages sended by the canbus of the 18F2480 and from MCP2510 connected to the 16F876.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 21, 2009 2:58 pm     Reply with quote

1. Put printf statements in your program to trace the program flow.
See if the program is locking up on one line of code, such as the call
to can_init().

2. Look at the RESET pin on the MCP2510. Make sure the chip is not
being held in reset.

3. Check the oscillator pin on the MCP2510. Make sure it has a
signal of the correct frequency and amplitude coming into it.

4. Check the Vdd voltage on the MCP2510. Make sure it's +5v.

5. Look at the SPI signals going to/from the MCP2510 chip. Make sure
they are present.

6. Run the MCP2510 in loopback mode. See if it works. See this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=39809

In other words, trouble-shoot the problem.
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