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 Bus 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: Sun Jan 12, 2014 9:53 pm     Reply with quote

I wanted to comment on this suspicion of mine before, but I didn't because
both your schematic and your photo of the boards are badly out of focus.
But I ran a sharpening filter on the photo of your boards and that helped
a little.

I don't think you have any 0.1 uF ceramic bypass caps on your chips at all.
That's a major problem. Every Vdd, AVdd, and Vcc pin on the MCP2515,
dsPIC30F4011, and MCP2551 should have a 0.1 uF cap placed very close
to the pin, and the other side of the cap should quickly connect to a
ground layer or plane. Look at the last page of the CCS exercise book
pdf that you posted. It shows a board outline. You will see the little
ceramic caps near every chip.

Originally I didn't see any caps shown on your schematic. I sort of
assumed or hopefully assumed that you had them on the board anyway.
That's why I didn't comment on it. But I couldn't tell for sure because
the board photos are so fuzzy. So I dropped the topic.

But now, looking at it again, not only do the chips not have caps, but
the voltage regulator has no caps on it. The 7805 regulator needs to
have a 10 uF / 16v tantalum cap connected between the output pin and
ground. It needs to be placed close to the regulator. I don't know what
your regulator input voltage is. Let's says it's 9 volts dc. Then put a
10 uF / 25v tantalum cap between the input pin and ground.

Also, what PIC programmer are you using ? The Microchip ICD and
pickit programmers, etc., do not recommend a cap on the MCLR pin.
All they want is a single 10K resistor to Vdd.
Wolf



Joined: 23 Sep 2011
Posts: 32

View user's profile Send private message AIM Address

PostPosted: Mon Jan 13, 2014 8:03 pm     Reply with quote

It's weird but it looks like it works now...

Code:

#include <30F4011.h>
#DEVICE DSPIC30F4011
#DEVICE *=16 ICD=TRUE ADC=10
#fuses PR,FRC_PLL16,NOWDT,NOPUT
#use delay(clock=117.92M)
#use rs232(baud=9600,UART2) //UART1A)
#use i2c(master, sda=PIN_F2, scl=PIN_F3)

#define EXT_CAN_CS   PIN_B1
#define EXT_CAN_SI   PIN_B2
#define EXT_CAN_SO   PIN_B4
#define EXT_CAN_SCK  PIN_E5

#include <can-mcp251x.c>

#define BLUE_STAT1_LED      PIN_E4
#define YELLOW_STAT2_LED    PIN_E2
#define BUZZER              PIN_E1
#define TOGGLE_SWITCH1      PIN_D2
#define TOGGLE_SWITCH2      PIN_F1
#define TOGGLE_SWITCH3      PIN_F0

#define BOARD1_ID  24
#define BOARD2_ID  25

// Uncomment this line to compile code for Board #1.
// Comment it out to compile for Board #2.
#define BOARD1   1

void main() {
    char chrTestLoop;
    struct rx_stat rxstat;
    int32 rx_id;
    int32 tx_id;
    int8 rx_len;
    int8 buffer[8];

    set_tris_b(0x0011);
    set_tris_c(0x6000);
    set_tris_d(0x000F);
    set_tris_e(0x0100);
    set_tris_f(0x0013);

    //AAA:
    printf("Startup Text\n\r");

    //goto AAA;

    can_init();

    #ifdef BOARD1   // For Board #1

    while (1) {
        for (chrTestLoop = 33; chrTestLoop < 123; chrTestLoop++) {
            buffer[0] = chrTestLoop;
            can_putd(BOARD2_ID, buffer, 1, 1, 1, 0);
            printf("Character %c has been sent to CAN network\n\r", buffer[0]);
            delay_ms(250);
        }
    }

    #else  // For Board #2
    while(1) {
        if(can_kbhit()) {
            if(can_getd(rx_id, buffer, rx_len, rxstat)) {
                printf("Received char %c from RX id %d\n\r", buffer[0], rx_id);
            }
        }
    }
    #endif
}


On TX Terminal Window:
Code:

Character h has been sent to CAN network
Character i has been sent to CAN network
Character j has been sent to CAN network
Character k has been sent to CAN network
Character l has been sent to CAN network
Character m has been sent to CAN network
Character n has been sent to CAN network
Character o has been sent to CAN network
Character p has been sent to CAN network
Character q has been sent to CAN network
Character r has been sent to CAN network
Character s has been sent to CAN network


On RX Terminal Window:
Code:

Received char h from RX id 25
Received char i from RX id 25
Received char j from RX id 25
Received char k from RX id 25
Received char l from RX id 25
Received char m from RX id 25
Received char n from RX id 25
Received char o from RX id 25
Received char p from RX id 25
Received char q from RX id 25
Received char r from RX id 25
Received char s from RX id 25


It looks like there was an ID miss match in my code and my power supplies could be putting out some bad power that needs more caps. But other then that, this CAN stuff looks like it works now.

Yes, I dropped the ball on all the caps, I will have to tweek the boards and stuff them in the circuit. Oh and I'm using the MPLAB ICD3. I'm glad this is just a REV A, because I will have some fancy soldering work to do now. I never realized how sensitive these components really are.

Thank you for all your help and being patient with me.
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