|
|
View previous topic :: View next topic |
Author |
Message |
donmezbilek
Joined: 06 Jan 2024 Posts: 4
|
MCP2561 CANBUS COMMUNICATION ERROR |
Posted: Wed Jul 17, 2024 12:04 am |
|
|
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
|
|
Posted: Thu Jul 18, 2024 12:08 am |
|
|
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
|
|
Posted: Thu Jul 18, 2024 4:39 am |
|
|
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. |
|
|
|
|
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
|