jemly
Joined: 13 May 2007 Posts: 34
|
CAN - question about multiple messages and transmit buffers |
Posted: Mon Oct 15, 2007 3:49 am |
|
|
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!) |
|