|
|
View previous topic :: View next topic |
Author |
Message |
james_jeramiiz
Joined: 14 Aug 2016 Posts: 1 Location: Thailand
|
dspic33EP CAN issue please help. |
Posted: Sun Aug 14, 2016 11:40 am |
|
|
Hi, I'm currently working on CAN bus for reading data from ECM.
Now I'm using dsPIC33ep32GP502 with external 12M XTAL and SN65HVD230 CAN transceiver.
I have 120 Ohms resistor between CANH and CANL
I'm quite sure with physical layer.
My compiler version's 5.015.
I'm already check the oscillator by using loopback mode and oscilloscope. The pulse width on CANTX is exactly 1us.
When I try to read CAN bus using can_getd
the data from ECM should be in ID=0xE8 with 1Mbaud.
But the result is wrong.
Here is the image.
The ID I got change randomly from 2>102>202>302>402>502>602
I've tried reading with PIC24HJ256GP610A and It's work fine.
I've read the data sheet and ref manual from microchip and calculate baud rate. I'm not sure if there somthing wrong in datasheet or in the library.
Is Fcan = Fcy or Fcy/2 or Fcy*2 ?
Here is my code.
Code: | #include <33EP32GP502.h>
#device ADC=12
#FUSES NOWDT //Watch Dog Timer
#FUSES WPRES32 //Watch Dog Timer PreScalar 1:32
#FUSES WPOSTS8 //Watch Dog Timer PostScalar 1:128
#FUSES NOJTAG //JTAG disabled
#FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
#device ICSP=1
#use delay(clock=40MHz,crystal=12MHz)
#pin_select U1TX=PIN_B5
#pin_select U1RX=PIN_B6
#use rs232(UART1, baud=1000000, errors, stream=UART_PORT1)
#use i2c(MASTER, I2C1, SLOW, SMBUS, stream=I2C_PORT1)
#define CAN_DO_DEBUG TRUE
#define CAN_USE_EXTENDED_ID FALSE
#define CAN_BRG_PRESCALAR 0
#define CAN_BRG_PROPAGATION_TIME 4
#define CAN_BRG_PHASE_SEGMENT_1 7
#define CAN_BRG_PHASE_SEGMENT_2 5
#define CAN_BRG_SYNCH_JUMP_WIDTH 0
#define CAN_BRG_SAM FALSE
#define CAN_BRG_WAKE_FILTER FALSE
#define CAN_BRG_SEG_2_PHASE_TS TRUE
#pin_select C1TX = PIN_B10
#pin_select C1RX = PIN_B11
#include <can-PIC24.c>
void main()
{
int j;
for (j=0;j<8;j++) {
out_data[j]=0xAA;
in_data[j]=0;
}
can_init();
can_enable_b_transfer(TRB7);
enable_interrupts(INT_TIMER5);
enable_interrupts(INTR_GLOBAL);
delay_ms(1000);
printf("can_test!!\r\n");
//can_set_mode(CAN_OP_LOOPBACK);
while(TRUE)
{
//restart_wdt();
//if (can_tbe()){
//can_putd(tx_id, out_data, tx_len,tx_pri,tx_ext,tx_rtr);
//}
if (can_kbhit())can_getd(rx_id, &in_data[0], rx_len, rxstat);
delay_ms(1);
}
} |
I think there is something wrong with baudrate setting.
What am I missing?
Please help. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Sun Aug 14, 2016 12:55 pm |
|
|
Depends on the CANCKS bit.
Fp, is Fosc/2. This is the clock used if CANCKS=0. If CANCKS=1, this is multiplied by 2.
However your problem won't be baud (if the pulse width is 1uSec), but the segment times. Using your master oscillator every calculator I try, gives different figures for the segment widths than you have....
Also SJW=0, implies no bus ability to recover from any form of timing error. 1 is the normal minimum for this. |
|
|
|
|
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
|