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

CAN - question about multiple messages and transmit buffers

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



Joined: 13 May 2007
Posts: 34

View user's profile Send private message

CAN - question about multiple messages and transmit buffers
PostPosted: Mon Oct 15, 2007 3:49 am     Reply with quote

I have used the CCS example to write a bit of software which needs to send out data using CAN. Essentially I need to send 5 packets of 8 bytes but at the moment the receive side is only seeing the first 3 (we are using CANKing to monitor as well so we know the problem is on the tx side not the rx).

Here is my code :

Code:


if ( can_tbe() )
      {
         result01=can_putd(tx_id01, out_data01, tx_len,tx_pri,tx_ext,tx_rtr); //put data on transmit buffer
         result02=can_putd(tx_id02, out_data02, tx_len,tx_pri,tx_ext,tx_rtr); //put data on transmit buffer
         result03=can_putd(tx_id03, out_data03, tx_len,tx_pri,tx_ext,tx_rtr); //put data on transmit buffer
         result04=can_putd(tx_id04, out_data04, tx_len,tx_pri,tx_ext,tx_rtr); //put data on transmit buffer
         result05=can_putd(tx_id05, out_data05, tx_len,tx_pri,tx_ext,tx_rtr); //put data on transmit buffer
               
         if (result01 == 0xFF) output_bit(CAN_01_ERROR_LED,1);
         if (result02 == 0xFF) output_bit(CAN_02_ERROR_LED,1);
         if (result03 == 0xFF) output_bit(CAN_03_ERROR_LED,1);
         if (result04 == 0xFF) output_bit(CAN_04_ERROR_LED,1);
         if (result05 == 0xFF) output_bit(CAN_05_ERROR_LED,1);
         
         
      }


I check the transmit buffer is empty once and then send the lot - my first guess was that the tx buffers were full once it got to the 4th msg but then why is the error led for this msg not lighting up?

I also tried:

Code:

if ( can_tbe() )
      {
         result01=can_putd(tx_id01, out_data01, tx_len,tx_pri,tx_ext,tx_rtr); //put data on transmit buffer
         result02=can_putd(tx_id02, out_data02, tx_len,tx_pri,tx_ext,tx_rtr); //put data on transmit buffer
         result03=can_putd(tx_id03, out_data03, tx_len,tx_pri,tx_ext,tx_rtr); //put data on transmit buffer
         if(can_tbe())
         {
            result04=can_putd(tx_id04, out_data04, tx_len,tx_pri,tx_ext,tx_rtr); //put data on transmit buffer
         }
         
         result05=can_putd(tx_id05, out_data05, tx_len,tx_pri,tx_ext,tx_rtr); //put data on transmit buffer
               
         if (result01 == 0xFF) output_bit(CAN_01_ERROR_LED,1);
         if (result02 == 0xFF) output_bit(CAN_02_ERROR_LED,1);
         if (result03 == 0xFF) output_bit(CAN_03_ERROR_LED,1);
         if (result04 == 0xFF) output_bit(CAN_04_ERROR_LED,1);
         if (result05 == 0xFF) output_bit(CAN_05_ERROR_LED,1);
         
         
      }


....but the second check of the tx buffer was still returning true which has left me stumped as to why I can't get the 4th and 5th messages through each time. Can anyone help?? Here's some other useful info about what I am running:

PIC 18F4680 @40Mhz.
I am receiving serial data at a baud rate of 38400 from a 3rd party piece of software. This data is sent out 50 times a second and we are receiving it all fine - each time the 'useful data' buffer is full we send the data out using CAN. Finally, some variables:

Code:

int out_data01[8];
int out_data02[8];
int out_data03[8];
int out_data04[8];
int out_data05[8];

//CAN TX IDs
int32 tx_id01=1;
int32 tx_id02=2;
int32 tx_id03=3;
int32 tx_id04=4;
int32 tx_id05=5;

int1 tx_rtr=0;
int1 tx_ext=0;
int tx_len=8;
int tx_pri=3;


Any help / suggestions would be great.... (PS: this is the first time we have used CAN so apologies if this is blindingly obvious!)
jemly



Joined: 13 May 2007
Posts: 34

View user's profile Send private message

PostPosted: Mon Oct 15, 2007 6:11 am     Reply with quote

Ok I've got this sorted now so I'm posting the solution for anyone who may ever need it.

By default the PIC 18F4680 has only 3 TX buffers set up. It has 6 programmable buffers which can be configured as either RX and TX and used in addition to the first 3.

In order to set all as TX buffers you would need this to initialise and configure:

Code:

   can_init();   //standard insitialise routine
   can_set_functional_mode(can_mode);  //set functional mode 1 to allow use of extra 6 buffers
   can_enable_b_transfer(can_tx_buffers); //set all 6 as TX


Hope this helps someone else!
jemly



Joined: 13 May 2007
Posts: 34

View user's profile Send private message

PostPosted: Mon Oct 15, 2007 6:12 am     Reply with quote

Sorry I meant to show what the important values were!

Code:

byte can_mode = 0x01;
byte can_tx_buffers = 0xFC;
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