hi
can anyone tell me which flag should be enabled for transmitting data on CAN in MC9S12XHZ512 controller.
I want to send some CAN request data from controller after certain time interval.
For this should I set CAN0TFLG =1 so that it automatically reaches to interrupt function or is there any other register .
let me know if anyone has some idea
rgds
SARY
There are 3 CAN TX buffers. There are three corresponding "TX buffer is empty" flags in CANxTFLG register. And there are three "TX buffer is empty"-interrupt enable bits in CANxTIER register.
If you want interrupt on TX buffer 0 is empty, then you do CAN0TIER |= CAN0TIER_TXEIE0_MASK; .
If you want interrupt on any TX buffer is empty, then you set all three TXEIE bits.
You do CAN0TFLG = CAN0TFLG_TXE0_MASK; to clear buffer 0 flag and send TX buffer 0. TX1 - for TX buffer 1, TX2 - for TX buffer 2.
hi kef
I got the answer .I can transmit data using this. But there is another problem coming.It always keeps on sending same data even if I have changed data.
Like I want to send two request,I am sending them like
///Fuel cons req. uisng EA00 PGN
CAN0TFLG|=CAN0TFLG_TXE0_MASK;
Fuel_cons=(unsigned long)J1939TripFuelCalc;//reading fuel cons data
///Eng hours req. uisng EA00 PGN
CAN0TFLG|=CAN0TFLG_TXE0_MASK;
EngHr=J1939HrsCalc;//reading engine hrs
But I am able to receive only first request message.I cant receive second request message.
so what could be the posible reason for that.even I tried to put some delay between the two request.
but still its not coming.
wating for reply
Thanks
SARY
First of all, ORing CANTFLG with something is wrong!
CAN0TFLG|=CAN0TFLG_TXE0_MASK;
^^ this clears not only TXE0 bit, but also TXE1 and TXE0 if they are set! In other words if TX1 and TX2 buffers are empty, then red line with send those empty buffers.
CAN0TFLG = CAN0TFLG_TXE0_MASK;
^^ this will send only buffer TX0.
I don't see where are you filling TX buffers. I hope you fill TX buffer only when TXE0 bit is set. Is it so? Because your code looks bit weird: 1) you send TX0 buffer, 2) you do something to Fuel_cons, 3) you send TX0 buffer again, though I don't see where you are waiting for TX0 buffer to become empty (while TXE0 is clear), 4) you do something to EngHr
I have removed Oring also.It is behaving in the same manner.And I am putting data in the transmit buffer in the CAN transmit interrupt function.Code is somewhat like below
CAN0TBSEL = CAN0TFLG; // Select lowest empty buffer
u8TxBuffer = CAN0TBSEL; // Backup selected buffer
*((unsigned long*) ((unsigned long)(&CAN0TXIDR0)))= u32ID;
// Load data to Data Segment Registers
for (i=0;i<u8Length;i++) {
*(&CAN0TXDSR0 + i) = u8TxData[i];
}
CAN0TXDLR = 8; // Set Data Length Code
CAN0TXTBPR = 1; // Set Priority
CAN0TFLG = u8TxBuffer; // Start transmission
while ( (CAN0TFLG & u8TxBuffer) != u8TxBuffer);
return;
But I am able to receive Only one data(request frame) in regular intervals.
I want to know how can I transmit two data frames(request) one after the other in regular intervals.
SARY
while(!((CAN0TFLG ==0x7)||(CAN0TFLG == 0x6)));
CAN0TBSEL = CAN0TFLG;
CAN0TXIDR3 = (unsigned char)((id & 0x7f)<<1) ;
CAN0TXIDR2 = (unsigned char)((id>>7) & 0xff) ;
CAN0TXIDR1 = (unsigned char)(((id>>15) & 0x07) | 0x18 | ((id>>13) & 0xe0));
CAN0TXIDR0 = (unsigned char)((id >> 21) & 0xff);
CAN0TXDSR0 = packet[0];
CAN0TXDSR1 = packet[1];
CAN0TXDSR2 = packet[2];
CAN0TXDSR3 = packet[3];
CAN0TXDSR4 = packet[4];
CAN0TXDSR5 = packet[5];
CAN0TXDSR6 = packet[6];
CAN0TXDSR7 = packet[7];
CAN0TXDLR = length;
CAN0TXTBPR = 0;
CAN0TFLG = CAN0TBSEL;