|
|
View previous topic :: View next topic |
Author |
Message |
shashank27187
Joined: 28 Jul 2009 Posts: 13
|
loopback not working |
Posted: Wed Aug 05, 2009 12:54 am |
|
|
i have tried various programs to make the CAN node work but it is not working
here is the loop back code i've used:
Code: | #include <18F2585.h>
#fuses HS, NOWDT, NOPROTECT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8)
//#define CAN_DO_DEBUG 1
#include <can-18xxx8.c>
void main(void) {
int32 can_id;
int can_data[8];
int can_length, counter;
struct rx_stat rxstat;
can_init();
printf("\n\r CAN example");
printf("Starting");
can_set_mode(CAN_OP_LOOPBACK);
counter = 0;
printf("loop back ok");
can_data[0] = 0x55;
while(1)
{
if(kbhit())
{
getch();
if(can_putd(42, can_data, 1, 3, TRUE, FALSE))
printf("tx ok");
while(!can_kbhit());
if(can_getd(can_id, &can_data[0], can_length, rxstat))
printf("rx ok");
counter++;
}
}
} |
the code works till it prints "starting" ... i.e. can node is initialised but the loopback statement does not executes at all.
Pls... Anybody could tell me what would be the reason... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 05, 2009 1:20 am |
|
|
Please don't start a new thread every time you have another question
on CAN bus loopback mode. You already have an thread here:
http://www.ccsinfo.com/forum/viewtopic.php?t=39792
Add any new questions on the CAN bus to your existing thread.
That's what a thread is for. |
|
|
shashank27187
Joined: 28 Jul 2009 Posts: 13
|
|
Posted: Fri Aug 07, 2009 4:26 am |
|
|
Thanks..PCM I got the code working... there was some flaw in the hardware.
Ok. i have one more problem..
The micro needs to be reset some 5-6 times before it starts working.. could anybody tell me wat would be the reason. but when it starts working it works well..... pls.. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Aug 07, 2009 4:58 am |
|
|
PCM programmer wrote: | Add any new questions on the CAN bus to your existing thread.
That's what a thread is for. |
shashank27187 wrote: | Ok. i have one more problem.. |
What is the part you didn't understand? |
|
|
shashank27187
Joined: 28 Jul 2009 Posts: 13
|
|
Posted: Wed Aug 12, 2009 2:39 am |
|
|
The working in the loop back mode got stopped..... it happened just once and is not repeating at all.
I'm implementing one node for the time being.
actually, i referred to the topics and discussions mentioned in the forum and found that the problem exists in the change from configuration mode to the loopback mode.
The PIC 18f2585 works well in normal mode.i.e it tries to send the data to the CANTX and RX pins as the LED toggles as per the program.
But in can-18xxx8.c i put break points in the mode set part, but found that the mode is not at all changing to the loop back mode from the configuration mode.
I'm putting the code for reference.... pls suggest something....
Code: |
#include <18f2585.h>
#fuses HS,NOPROTECT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
#include <can-18xxx8.c>
#define CAN_ENABLE_DRIVE_HIGH 1
#define CAN_BRG_PRESCALER 1
#define CAN_BRG_SYNC_JUMP_WIDTH 0
#define CAN_BRG_PROPAGATION_TIME 0
#define CAN_BRG_PHASE_SEGMENT 3
#define CAN_BRG_SAM 0
#define CAN_BRG_SEG_2_PHASE_TS 1
#define CAN_BRG_PHASE_SEGMENT_2 1
#define CAN_BRG_WAKE_FILTER 0
void can_initialize_mode(void);
void main()
{
struct rx_stat rxstat;
int can_length,counter;
int32 can_id;
int8 rx_len;
int8 can_data[8];
output_high(PIN_B0);
delay_ms(1000);
output_low(PIN_B0);
delay_ms(2000);
printf("\n above CAN init functon\n");
can_init();
can_set_mode(CAN_OP_LOOPBACK);
printf("\n this is the mode %d", CAN_OP_LOOPBACK);//does not prints
can_data[0]=0x55;
while(1)
{
if( kbhit())
{
getch();
printf("\n the data loaded is %c",can_data[0]);
if (can_putd(42,can_data,1,3,TRUE,FALSE))
printf(" tx ok ");
while(!can_kbhit());
if (can_getd(can_id,&can_data[0],can_length,rxstat))
printf("rx ok");
counter++;
}
}
} |
The break points in the CAN header file are put as...
Code: |
void can_set_mode(CAN_OP_MODE mode) {
CANCON.reqop=mode;
printf("\r\nI am in mode change..."); //this is printed for change to //config mode and loopback mode as it is called twice
while( (CANSTAT.opmode) != mode );
} |
In the initializaton function.....
Code: |
void can_init(void) {
can_set_mode(CAN_OP_CONFIG); //must be in config mode before params can be set
can_set_baud();
RXB0CON=0;
RXB0CON.rxm=CAN_RX_VALID;
RXB0CON.rxb0dben=CAN_USE_RX_DOUBLE_BUFFER;
RXB1CON=RXB0CON;
CIOCON.endrhi=CAN_ENABLE_DRIVE_HIGH;
CIOCON.cancap=CAN_ENABLE_CAN_CAPTURE;
can_set_id(RX0MASK, CAN_MASK_ACCEPT_ALL, CAN_USE_EXTENDED_ID); //set mask 0
can_set_id(RX0FILTER0, 0,CAN_USE_EXTENDED_ID ); //set filter 0 of mask 0
can_set_id(RX0FILTER1, 0, CAN_USE_EXTENDED_ID); //set filter 1 of mask 0
can_set_id(RX1MASK, CAN_MASK_ACCEPT_ALL, CAN_USE_EXTENDED_ID); //set mask 1
can_set_id(RX1FILTER2, 0, CAN_USE_EXTENDED_ID); //set filter 0 of mask 1
can_set_id(RX1FILTER3, 0, CAN_USE_EXTENDED_ID); //set filter 1 of mask 1
can_set_id(RX1FILTER4, 0, CAN_USE_EXTENDED_ID); //set filter 2 of mask 1
can_set_id(RX1FILTER5, 0, CAN_USE_EXTENDED_ID); //set filter 3 of mask 1
set_tris_b((*0xF93 & 0xFB ) | 0x08); //b3 is out, b2 is in
can_set_mode(CAN_OP_LOOPBACK);
printf("\n this is the mode %d", CAN_OP_LOOPBACK);// does not prints...
} |
thanks in advance.... |
|
|
|
|
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
|