View previous topic :: View next topic |
Author |
Message |
Bill24
Joined: 30 Jun 2012 Posts: 45
|
CAN bus problem [solved] |
Posted: Wed Aug 29, 2012 2:20 am |
|
|
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
|
|
Posted: Wed Aug 29, 2012 7:04 am |
|
|
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
|
|
Posted: Wed Aug 29, 2012 11:36 pm |
|
|
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
|
|
Posted: Thu Aug 30, 2012 9:33 am |
|
|
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. |
|
|
|