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

MCP2561 CANBUS COMMUNICATION ERROR

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



Joined: 06 Jan 2024
Posts: 4

View user's profile Send private message AIM Address

MCP2561 CANBUS COMMUNICATION ERROR
PostPosted: Wed Jul 17, 2024 12:04 am     Reply with quote

Hello, I have built a CAN communication circuit using the PIC18F25K83 microcontroller. I only want to send data. I used the MCP2561 CAN transceiver. The pin configuration is as follows: Tx -> B4, Rx -> B3, STBY -> B5. However, I am experiencing problems with the communication. Could you help me with a few issues?

1-) Can you review the code below to see why I can't communicate?
2-) How do we set the bitrate?

My Code:
#include <testcode4.h>
/*
#define CAN_USE_EXTENDED_ID TRUE
#define CAN_BRG_SEG_2_PHASE_TS TRUE
#define CAN_BRG_PRESCALAR 4
#define CAN_BRG_SYNCH_JUMP_WIDTH 0
#define CAN_BRG_PROPAGATION_TIME 2
#define CAN_BRG_PHASE_SEGMENT_1 5
#define CAN_BRG_PHASE_SEGMENT_2 5
#define CAN_BRG_WAKE_FILTER FALSE
#define CAN_BRG_SAM TRUE */
#include "can-18F4580-A.c"

unsigned int8 data[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};

}
void main()
{
setup_adc_ports(sAN0 | sAN1 | sAN2 | sAN3 | sAN4 | sAN5, VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL | ADC_TAD_MUL_0 | ADC_LEGACY_MODE | ADC_THRESHOLD_INT_DISABLED);

output_low(PIN_B5);
delay_ms(100);
output_high(BUZZER);
delay_ms(100);
output_low(BUZZER);
delay_ms(100);


can_init();
can_putd(0x100,data,8,1,TRUE,FALSE);
delay_ms(1000);
//can_set_mode(CAN_OP_CONFIG);

//can_set_functional_mode(CAN_FUN_OP_ENHANCED);

//can_enable_b_transfer(B4);

//can_set_mode(CAN_OP_NORMAL);

while ( TRUE )
{

can_putd(0x100,data,8,1,TRUE,FALSE);
delay_ms(1000);

}

}
Testcode:

#include <18F25K83.h>
#device ADC=12

#fuses NOWDT

//#use delay(internal=64mhz)
#use delay(crystal=20000000)
#use FIXED_IO( B_outputs=PIN_B5,PIN_B2,PIN_B1,PIN_B0 )
#use FIXED_IO( C_outputs=PIN_C7,PIN_C5,PIN_C4,PIN_C3,PIN_C2 )
#define RL1 PIN_B0
#define RL2 PIN_B1
#define RL3 PIN_B2
#define CAN_STBY PIN_B5
#define BUZZER PIN_C2
#define SRCLK PIN_C3
#define RCLK PIN_C4
#define SER PIN_C5
#define MOSFET PIN_C7
Ttelmah



Joined: 11 Mar 2010
Posts: 19495

View user's profile Send private message

PostPosted: Thu Jul 18, 2024 12:08 am     Reply with quote

The first thing is you need to use one of the online calculator tools to
get the correct settings for your clock rate and the CAN speed you are using.
You don't tell us the CAN rate you are trying to use, but the timings you
show look to be for a much slower master oscillator than you are using.
(Actually for possibly something like a 20MHz clock).
However there is a huge problem. CAN requires accurate timings. Normally
you try to be within less than 1% error on the CAN rates. The internal
oscillator may well not be accurate enough to actually work reliably with
CAN, depending on how close the division you have to use for the speed
you are using.
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jul 18, 2024 4:39 am     Reply with quote

also....
CAN requires proper terminators AND twisted pair wiring.

Found THAT out when wife's Nissan went 'funny'. Dealer never installed remote start computer properly...sigh.......5 trips,they didn't FIX it.....

While it may not be your specific problem,check to be sure the hardware is 100%, might save you from getting a full head of gray head !!

As Mr. T says, Can is 'fussy' about timing, seems to be 'overly complicated' for a communications system.
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