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 support@ccsinfo.com

CCS CAN Bus dev board - auto RTR problem

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



Joined: 15 Sep 2003
Posts: 75

View user's profile Send private message

CCS CAN Bus dev board - auto RTR problem
PostPosted: Mon Jan 22, 2007 4:33 am     Reply with quote

In section 18 of the exercise book, I cannot get the auto RTR to work. All I got from Node B was the following (via RS232):

Data received!
0 0 0 0 0 0 0 0
00000500

and repeats...

The 'receive' buffer is all 0's, and rx_len is also 0. The can_kbhit() function returned a 1. The ID received is correct at 0x500.

Ideally, it should be the following (according to the exercise book):
Data received!
15 14 13 12 11 10 9 8
00000500

and repeats...

I have included the code for Nodes A and B (see below). I would appreciate any comments.


Node A:
Code:

#include <18F4580.h>
//#device ICD=TRUE
#fuses HS,NOPROTECT,NOLVP,NOWDT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <can-18F4580.c>

void main()
{
   int32 rx_id;
   int rx_len, i;
   struct rx_stat stat;
   int data[8]={15,14,13,12,11,10,9,8};
   int receive[8];

   can_init();

   can_set_functional_mode(1);

   can_enable_b_transfer(B1);

   can_disable_filter(0xFFFF);
   can_enable_filter(0x01);

   can_set_id(RX0MASK,0xFF00,TRUE);
   can_set_id(RXFILTER0,0x500,TRUE);
   can_set_id(B1ID,0x500,TRUE);

   can_associate_filter_to_mask(ACCEPTANCE_MASK_0,F0BP);
   can_associate_filter_to_buffer(AB1,F0BP);

   can_load_rtr(B1,data,8);
   can_enable_rtr(B1);

   while(TRUE);
}


Node B:
Code:

#include <16F876A.h>
//#device ICD=TRUE
#fuses HS,NOPROTECT,NOLVP,NOWDT
#use delay(clock=2500000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <can-mcp2510.c>

void main()
{
   int32 rx_id=0;
   int rx_len=0, i;
   struct rx_stat stat;
   int data[8]={7,6,5,4,3,2,1,0};
   int receive[8]={0,0,0,0,0,0,0,0};

   can_init();

   while(TRUE)
   {
      can_putd(0x500,data,8,3,TRUE,TRUE);
      delay_ms(1000);

      if ( can_kbhit() )
      {
          can_getd(rx_id, receive, rx_len, stat);
          printf("Data received!\n\r");
          for(i=0; i<8; i++)
             printf("%i ",receive[i]);

          printf("\n\r%Lx\n\r",rx_id);
      }
      else
      {
          printf("Data not received.\n\r");
      }
   }
}
sjbaxter



Joined: 26 Jan 2006
Posts: 141
Location: Cheshire, UK

View user's profile Send private message Visit poster's website

PostPosted: Mon Jan 22, 2007 10:49 am     Reply with quote

I haven't used the CAN dev board, but from your code I suspect the nodes are running at different CAN bit rates.

My assumption is based on NodeA has a #using delay(20000000) and NodeB is set up to be #using delay(2500000).

At no point do you then set the baud rate of the CAN controller other than a standard call to can_init() which will set the baud rate registers to the same values (and based on different clocks ... will give different bit rates !!!).

BTW: RTR is a CAN feature that is not generally used in 'real world' applications. If you haven't already got the nodes talking using simple tx and rx can messages, then I would get that working before moving onto RTR.
_________________
Regards,
Simon.
TL



Joined: 15 Sep 2003
Posts: 75

View user's profile Send private message

PostPosted: Mon Jan 22, 2007 4:20 pm     Reply with quote

Thanks for replying.

According to the exercise book, all nodes on the bus have the same target bit time and the baud rate is set in can-18F4580.h and .c for Node A, and can-mcp2515.h and .c for Node B. Apart from EX7 and EX18, all the examples work satisfactorily. All other examples use 20MHz for Node A and 2.5MHz for Node B. Note: The MCP2515 in Node B has a prescaler of 8 which divides the 20MHz to 2.5MHz for the PIC16F876A. Therefore, I assume the bit timings and baud rates for both nodes are the same. However, I need to use some tables on the web to check the figures.

CCS have confirmed that in EX7, there is a configuration problem for GP7 pin of MCP25050, and therefore the decimal point of the 7-segment display does not work. However, they did not warn me (and I assume other users as well!) about this problem when I bought the dev kit. I have spent time in debugging it. They should warn users in order to save users time. I will tell them to either tell new users about it or change the wording in EX7.

I have also written to CCS regarding EX18, but I have yet to receive a reply from them for a few weeks.
rwskinner



Joined: 08 Dec 2006
Posts: 125
Location: Texas

View user's profile Send private message

PostPosted: Wed Jan 24, 2007 6:49 am     Reply with quote

TL wrote:
Thanks for replying.
.


The Can Dev board and examples are set for 125K. Unless you went in and changed the header files.

I haven't tried Auto RTR yet but everything else seemed to work after making it past all the typos and incorrect header file includes that don't exist.
TL



Joined: 15 Sep 2003
Posts: 75

View user's profile Send private message

PostPosted: Thu Jan 25, 2007 2:23 am     Reply with quote

Thanks for your information.
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