Part Number: TMS320F28069
Other Parts Discussed in Thread: TMS320F28335
Hi,
I am facing a problem in the implementation of Ecan it is not transmitting the data and receiving data. And there is no error showing in the code.
Below the code:
#include "F2806x_Device.h"
#include "DSP28x_Project.h"
#define RX_BUFFER_SIZE 16
Uint32 RxBuffer[RX_BUFFER_SIZE];
Uint32 RxBufferIndex = 0;
void InitECAN(void);
void CAN_TransmitMessage(void);
void CAN_ReceiveMessage(void);
__interrupt void CanIsr(void);
Uint32 TxMsgCount = 0;
Uint32 RxMsgCount = 0;
Uint8 ecan_rx_byte = 0;
Uint8 ecan_rx_buff[64];
void main(void)
{
//system init
InitSysCtrl();
//disable all interrupts
DINT;
//init pie vector for all interrupt line
InitPieCtrl();
// Disable all CPU interrupts
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW;
PieVectTable.ECAN0INTA = &CanIsr;
EDIS;
// //Enable globle interrupts and higher priority real time debugging
PieCtrlRegs.PIEIER1.bit.INTx1 =1; //Enable INT 1.1 in the PIE
IER |=M_INT1 ; //Enable CPU Interrupts
EINT; //Enable Globle interrupt
ERTM; //Enable Globle interrupt real time debugging
InitECAN();
for (;;)
{
DELAY_US(1000);
CAN_TransmitMessage();
CAN_ReceiveMessage();
}//for end
}//main end
void InitECAN(void)
{
EALLOW;
// Enable ECAN module clock
SysCtrlRegs.PCLKCR0.bit.ECANAENCLK = 1;
// Configure GPIO pins for ECAN-A
GpioCtrlRegs.GPAPUD.bit.GPIO30 = 0; // Enable pull-up for GPIO30 (CANRXA)
GpioCtrlRegs.GPAPUD.bit.GPIO31 = 0; // Enable pull-up for GPIO31 (CANTXA)
GpioCtrlRegs.GPAQSEL2.bit.GPIO30 = 3; // Asynch input GPIO30 (CANRXA)
GpioCtrlRegs.GPAMUX2.bit.GPIO30 = 1; // Configure GPIO30 as CANRXA
GpioCtrlRegs.GPAMUX2.bit.GPIO31 = 1; // Configure GPIO31 as CANTXA
// Configure CAN controller
ECanaRegs.CANGAM.bit.AMI = 1; // Global acceptance mask mode
ECanaRegs.CANMIM.all = 0; // Clear all mailboxes to receive any message
ECanaRegs.CANGIF1.all = 0x01FF; // Clear all interrupt flags
ECanaRegs.CANMIL.all = 0; // Clear all mailbox interrupt levels
ECanaRegs.CANMIM.bit.MIM0 = 1; // Enable Mailbox 0 interrupt
ECanaRegs.CANMIL.bit.MIL0 = 1; // Set Mailbox 0 interrupt level
// Configure Mailbox 0 for receiving
ECanaMboxes.MBOX0.MSGCTRL.bit.DLC = 8; // Data length code
ECanaMboxes.MBOX0.MSGID.bit.IDE = 0; // Standard identifier
ECanaMboxes.MBOX0.MSGID.all = 0x201; // Message ID (11-bit)
ECanaMboxes.MBOX0.MSGID.bit.AME = 0; // Acceptance mask disabled
ECanaMboxes.MBOX0.MSGID.bit.AAM = 0; // Acceptance mask is don't care
ECanaRegs.CANMD.all = 0; // Clear the mailbox direction bits
ECanaRegs.CANMD.bit.MD0 = 1; // Mailbox 0 is a receive mailbox
// Configure Mailbox 1 for transmitting
ECanaMboxes.MBOX1.MSGCTRL.bit.DLC = 8; // Data length code
ECanaMboxes.MBOX1.MSGID.bit.IDE = 0; // Standard identifier
ECanaMboxes.MBOX1.MSGID.all = 0x200; // Message ID (11-bit)
ECanaMboxes.MBOX1.MSGID.bit.AME = 0; // Acceptance mask disabled
ECanaMboxes.MBOX1.MSGID.bit.AAM = 0; // Acceptance mask is don't care
ECanaRegs.CANMD.bit.MD1 = 0; // Mailbox 1 is a transmit mailbox
// Enable ECAN interrupts
ECanaRegs.CANMIM.bit.MIM0 = 1; // Enable Mailbox 0 interrupt
// Enable Global Interrupt (GINT) in the CAN control register
ECanaRegs.CANGIF1.all = 0xFFFFFFFF; // Clear all interrupt flags
ECanaRegs.CANGIM.bit.GIL = 1; // Enable global interrupt line l`
// Enable CAN interrupts in the PIE
PieCtrlRegs.PIEIER9.bit.INTx5 = 1; // Enable ECAN-A0 interrupt in PIE
IER |= M_INT9; // Enable group 9 interrupts
EINT; // Enable global interrupts
ERTM; // Enable global real time interrupt
// Start CAN module
// ECanaRegs.CANGAM.bit.AMI = 1;
ECanaRegs.CANMC.bit.CCR = 1; // Set CCR to configure the CAN controller
while (ECanaRegs.CANES.bit.CCE != 0); // Wait for CCE to be cleared
{
}
// Configure the eCAN for self test mode
ECanaRegs.CANMC.bit.STM = 0;
EDIS;
}
void CAN_TransmitMessage(void)
{
// Check if Transmit Request (TXRQST) is set for Mailbox 1
if (ECanaRegs.CANTA.bit.TA1 == 1)
{
// Clear the TXRQST bit to acknowledge the request
ECanaRegs.CANTA.bit.TA1 = 1;
// Increment the transmit message count
TxMsgCount++;
ECanaMboxes.MBOX1.MDL.all = 0x01001010;
ECanaMboxes.MBOX1.MDH.all = 0x10101010;
ECanaRegs.CANTRS.all = (1 << 0);
}
}
void CAN_ReceiveMessage(void)
{
// Check if New Data flag is set for Mailbox 0
if (ECanaRegs.CANRMP.bit.RMP0 == 1)
{
// Copy the received data from Mailbox 0
RxBuffer[RxBufferIndex] = ECanaMboxes.MBOX0.MDL.all;
RxBuffer[RxBufferIndex + 1] = ECanaMboxes.MBOX0.MDH.all;
// increment the buffer index in a circular manner
RxBufferIndex = (RxBufferIndex + 2) % RX_BUFFER_SIZE;
// Clear the New Data flag
ECanaRegs.CANRMP.bit.RMP0 = 1;
// Increment the receive message count
RxMsgCount++;
}
}
__interrupt void
CanIsr(void)
{
// Acknowledge the interrupt
ECanaRegs.CANGIF0.bit.MIV0 = 0;
//
// To receive more interrupts from this PIE group, acknowledge this interrupt
PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;
}
Thanks and Regards
Siva Kumar