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 support@ccsinfo.com

CAN bus problem [solved]

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



Joined: 30 Jun 2012
Posts: 45

View user's profile Send private message

CAN bus problem [solved]
PostPosted: Wed Aug 29, 2012 2:20 am     Reply with quote

Compiler Version 4.135, PIC18F46K80

Can someone help me with a CAN problem. The code below is a stripped down test program. When using this with a Microchip CAN bus analyzer it appears a CAN message with ID 0 and data length 0 is continuously transmitted by the test program.

However the can_putd() never seems to output anything to the CAN bus.

Could this be due to the clock not being fast enough or jitter from being an internal clock ?

Any suggestion as to what I am missing greatly received.
Code:

#include "18F46K80.h"
#FUSES NOWDT                      //No Watch Dog Timer
#FUSES SOSC_DIG                  //Digital mode, I/O port functionality of RC0 and RC1
#FUSES HSM                            //High speed Osc, medium power 4MHz-16MHz
#use delay(int = 8000000)
#include "can-18F4580.h"

void main(void)
{
    // Send a request (tx_rtr=1) for 8 bytes of data (tx_len=8)
    unsigned int32 tx_id = MSG_TO_PMM;
    unsigned int1 tx_rtr = 1;
    unsigned int1 tx_ext = 0;
    unsigned int tx_len = 8;
    unsigned int tx_pri = 1;
    unsigned int out_data[8];

    // Perform initialisation.
    initialise();

    // Initialise CCS CAN Driver
    can_init();

   while (1)
    {   
        // Some test data
        out_data[0] = 0x31;
        out_data[1] = 0x41;
        out_data[2] = 0x51;
        out_data[3] = 0x61;
        out_data[4] = 100;   
        out_data[5] = 0;   
        out_data[6] = 0;   
        out_data[7] = 0;   

        can_putd(tx_id, out_data, tx_len,tx_pri,tx_ext,tx_rtr);

       delay_ms(1000);

    } // while (1)

I am using CCS driver with the can_set_baud() function changed to
Code:

// Values generated by Microchip Bit time Calculator for 500 kbits with 8MHz clock
BRGCON1 = 0x02;
BRGCON2 = 0x90;
BRGCON3 = 0x02;

Also for all filters ‘FALSE' has been used to use 11 bit CAN ID
Code:

can_set_id(RX1MASK, CAN_MASK_ACCEPT_ALL, FALSE);  //set mask 1
can_set_id(RXFILTER2, 0, FALSE);  //set filter 0 of mask 1
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Wed Aug 29, 2012 7:04 am     Reply with quote

Nothing looks obviously wrong, apart from setting the RTR bit while having a data payload. When I started with CAN I fell into the same trap. RTR packets cannot have a data payload! Try turning RTR off.

The clock speed or jitter shouldn't affect whether or not a packet is transmitted, just how (fast) it is transmitted.
_________________
Andrew
RHA



Joined: 25 Apr 2006
Posts: 31
Location: Germany

View user's profile Send private message

PostPosted: Wed Aug 29, 2012 11:36 pm     Reply with quote

For a first test the internal Clock is ok, but it is not stable enough for example when the temperature changes (I've had the problem).
Bill24



Joined: 30 Jun 2012
Posts: 45

View user's profile Send private message

PostPosted: Thu Aug 30, 2012 9:33 am     Reply with quote

andrewg wrote:
Nothing looks obviously wrong, apart from setting the RTR bit while having a data payload. When I started with CAN I fell into the same trap. RTR packets cannot have a data payload! Try turning RTR off.

The clock speed or jitter shouldn't affect whether or not a packet is transmitted, just how (fast) it is transmitted.


Turning RTR helped. Also comparing the signal on an oscilloscope showed that the transceiver was not working properly.


Thanks everyone.
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