AN2283 Freescale Semiconductor / Motorola, AN2283 Datasheet - Page 11

no-image

AN2283

Manufacturer Part Number
AN2283
Description
Scalable Controller Area Network (MSCAN)
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
/*******************************************************/
/*******************************************************/
@interrupt void trasmit_interrupt(void){
MOTOROLA
volatile unsigned char k;
volatile unsigned char length;
//Check to see if Transmit Buffer 0 is Empty
if (ctflg.TXE0 == 1){
//Load the priority into the transmit buffer.
ctcr.TXEIE0 = 0;
// Go to the address pointed to by the message’s *Data_Pointer from the Transmit Table and load in the data
// The number of data bytes in the message is loaded which is determined by length
tx_buffer0.Priority = index;
CTFLG = 0x01;
//The following is another method to clear the TXE flag to indicate this buffer is full in assembly language
//Notice that the LDA and STA instructions are used. DO NOT USE THE BSET Instructions.
tx_buffer0.ID0 = Tx_Table[index].ID;
tx_buffer0.DLC = Tx_Table[index].DLC; //Load the message’s DLC from the Transmit Table into the Transmit Buffer
length = tx_buffer0.DLC;
for(k=0; k<length; ++k){tx_buffer0.data[k] = *Tx_Table[index].Data + k;}
WARNING:
TRANSMITTER INTERRUPT
//Clear the TXE flag in the CTFLG register to indicate this buffer is full
// Disable the transmit interrupt that caused the interrupt
Motorola Scalable Controller Area Network (MSCAN) Interrupts
Steps involved in the transmit process using the transmit interrupt are:
Do not use the BSET instruction, or you will clear ALL the TXE bits. This is due
to the read, modify, and write operation of the BSET instruction. Instead LDA
and STA instructions or MOVE should be used. If programming in C, ensure
that the compiler is not performing the BSET instruction to perform these
operations.
The following sample code illustrates the above steps.
1. Find an empty transmit buffer as indicated by at least one of the transmit
2. Load the message contents (ID, DLC, Data, and Local Priority) into that
3. Clear the corresponding transmit buffer’s TXE flag to 0 indicating that
4. Enable the transmit interrupt for that buffer. To do this, set the
5. In the transmit interrupt routine, the user disables the transmit interrupt
//Store the Data Length of the message into a variable to be used in the next step
Freescale Semiconductor, Inc.
For More Information On This Product,
buffer empty flags (TXE2, TXE1, and TXE0) set to 1 in CTFLG.
empty transmit buffer.
the buffer is full. Keep in mind that these bits operate under the
“exclusive-OR” operation. When TXE = 1 (transmit buffer empty), write
a 1 to get TXE = 0 (transmit buffer full).
corresponding TXEIE bit to 1 in CTCR. The transmit interrupt will occur
when the state changes from TXE = 0 (buffer full) to TXE = 1 (buffer
empty). This occurs when the transmission of the message in the buffer
is completed with no errors and an acknowledgement is received.
by writing a 0 to the corresponding TXEIE that caused the interrupt in the
CTCR.
// Load the the message’s ID from the Transmit Table into the Transmit Buffer
Go to: www.freescale.com
The priority is the index value to the message in the Transmit Table.
Transmission Process Overview
AN2283/D
11

Related parts for AN2283