Other Parts Discussed in Thread: SYSBIOS
Hi,
I am trying the dcanTxRx.c starterware example code on AM335x based Phytech board. I am using CAN232 (from Gridconnect) to send the CAN data frames from AM335x to CAN232 (CAN232 is connected to Serial console terraterm). The CAN data frame transfer from AM335x to CAN 232 works fine (i'm able to see the packet received in the serial console) where as the CAN Receive from CAN232 to AM335x is not working. I am sending Data packet from Terraterm through CAN232 to AM335x which is not working.
I just connected 2 CAN232 modules and tried to send and Receive CAN frames, and it works fine. This was done to ensure that the CAN232 works fine for send and receive. I'm using the following code for CAN Receive at AM335x (Same code in dcanTxRx.c example).
main code
{
/* Enable the DCAN1 module clock */
DCANModuleClkConfig();
/* Perform the pinmux for DCAN1 */
DCANPinMuxSetUp(0);
/* Initialize the DCAN message RAM */
DCANMsgRAMInit(1);
/* Enable the processor IRQ */
IntMasterIRQEnable();
/* Register the DCAN interrupts */
DCANAintcConfigure();
/* Perform the DCAN configuration */
ConfigureDCAN();
index = CAN_NUM_OF_MSG_OBJS;
while(index--)
{
/* Invalidate all message objects in the message RAM */
CANInValidateMsgObject(SOC_DCAN_1_REGS, index, DCAN_IF2_REG);
}
entry.flag = rxflag;
// entry.id = canId;
entry.id = 0;
CANMsgObjectConfig(SOC_DCAN_1_REGS, &entry);
CANMsgObjectConfig(SOC_DCAN_1_REGS, &entry);
entry.flag = (CAN_EXT_FRAME | CAN_MSG_DIR_RX | CAN_DATA_FRAME);
entry.id = 0x00;
/*
** Configure a receive message object to accept CAN
** frames with extended ID.
*/
CANMsgObjectConfig(SOC_DCAN_1_REGS, &entry);
/* Start the CAN transfer */
DCANNormalModeSet(SOC_DCAN_1_REGS);
/* Enable the error interrupts */
DCANIntEnable(SOC_DCAN_1_REGS, DCAN_ERROR_INT);
/* Enable the interrupt line 0 of DCAN module */
DCANIntLineEnable(SOC_DCAN_1_REGS, DCAN_INT_LINE0);
while(1);
}
void CANRxObjectConfig(unsigned int baseAdd, can_frame* canPtr)
{
unsigned int idLen;
unsigned int msgIndex;
msgIndex = (CAN_NUM_OF_MSG_OBJS / 2);
idLen = (canPtr->flag & CAN_EXT_FRAME) ? DCAN_29_BIT_ID : DCAN_11_BIT_ID;
/* don't Use Acceptance mask. */
DCANUseAcceptanceMaskControl(baseAdd, DCAN_MASK_IGNORED, DCAN_IF2_REG);
// DCANUseAcceptanceMaskControl(baseAdd, DCAN_MASK_USED, DCAN_IF2_REG);
/* Configure the DCAN mask registers for acceptance filtering. */
// DCANMsgObjectMskConfig(baseAdd, DCAN_IDENTIFIER_MSK(DCAN_ID_MASK,
// DCAN_ID_MSK_11_BIT), DCAN_MSK_MSGDIR_DISABLE,
// DCAN_MSK_EXT_ID_ENABLE, DCAN_IF2_REG);
/* Set the message valid bit */
DCANMsgObjValidate(baseAdd, DCAN_IF2_REG);
/* Set the message id of the frame to be received */
DCANMsgIdSet(baseAdd, canPtr->id, idLen, DCAN_IF2_REG);
/* Set the message object direction as receive */
DCANMsgDirectionSet(baseAdd, DCAN_RX_DIR, DCAN_IF2_REG);
/* Enable the receive interrupt for the message object */
DCANMsgObjIntEnable(baseAdd, DCAN_RECEIVE_INT, DCAN_IF2_REG);
/* Enable the FIFO end of block */
DCANFIFOEndOfBlockControl(baseAdd, DCAN_END_OF_BLOCK_ENABLE, DCAN_IF2_REG);
/* Check for the message valid status for receive objects */
while((DCANMsgValidStatusGet(baseAdd, msgIndex)) &&
(msgIndex <= (CAN_NUM_OF_MSG_OBJS - 1)))
{
msgIndex++;
}
/* Configure the command register */
DCANCommandRegSet(baseAdd, (DCAN_ACCESS_CTL_BITS | DCAN_MSG_WRITE |
DCAN_ACCESS_MSK_BITS | DCAN_ACCESS_ARB_BITS),
msgIndex, DCAN_IF2_REG);
}
The ISR for DCAN Interrupt 0 is as follows.
static void DCANIsr0(void)
{
unsigned int errVal;
unsigned int data[2];
unsigned char *dataPtr;
unsigned int index = 0;
unsigned int msgNum;
if (DCANIntRegStatusGet(SOC_DCAN_1_REGS, 0xFFFF0000))
{
ConsoleUtilsPrintf("**INT1 is getting generated**\n");
}
while(DCANIntRegStatusGet(SOC_DCAN_1_REGS, DCAN_INT_LINE0_STAT))
{
if(DCANIntRegStatusGet(SOC_DCAN_1_REGS, DCAN_INT_LINE0_STAT) ==
DCAN_ERROR_OCCURED)
{
/* Check the status of DCAN Status and error register */
errVal = DCANErrAndStatusRegInfoGet(SOC_DCAN_1_REGS);
if(errVal & DCAN_MOD_IN_BUS_OFF_STATE)
{
ConsoleUtilsPrintf("**DCAN is in Bus-off state**\n");
/*
** This feature will automatically get the CAN bus to bus-on
** state once the error counters are below the error warning
** limit.
*/
DCANAutoBusOnControl(SOC_DCAN_1_REGS, DCAN_AUTO_BUS_ON_ENABLE);
}
if(errVal & DCAN_ERR_WARN_STATE_RCHD)
{
ConsoleUtilsPrintf("Atleast one of the error counters have");
ConsoleUtilsPrintf(" reached the error warning limit\n");
}
}
if((DCANIntRegStatusGet(SOC_DCAN_1_REGS, DCAN_INT_LINE0_STAT) !=
DCAN_NO_INT_PENDING) &&
((DCANIntRegStatusGet(SOC_DCAN_1_REGS, DCAN_INT_LINE0_STAT) !=
DCAN_ERROR_OCCURED)))
{
/* Get the number of the message object which caused the interrupt */
msgNum = DCANIntRegStatusGet(SOC_DCAN_1_REGS, DCAN_INT_LINE0_STAT);
/* Interrupt handling for transmit objects */
if(msgNum < (CAN_NUM_OF_MSG_OBJS/2))
{
/* Clear the Interrupt pending status */
CANClrIntPndStat(SOC_DCAN_1_REGS, msgNum, DCAN_IF1_REG);
isrTxFlag = 0;
if(value == index3)
{
/* Disable the transmit interrupt of the message object */
CANTxIntDisable(SOC_DCAN_1_REGS, msgNum, DCAN_IF1_REG);
/* Invalidate the transmit message object */
CANInValidateMsgObject(SOC_DCAN_1_REGS, msgNum, DCAN_IF1_REG);
}
}
if((msgNum >= (CAN_NUM_OF_MSG_OBJS/2)) && (msgNum < CAN_NUM_OF_MSG_OBJS))
{
/* Read a received message from message RAM to interface register */
CANReadMsgObjData(SOC_DCAN_1_REGS, msgNum, (unsigned int*) data, DCAN_IF2_REG);
/* Clear the Interrupt pending status */
CANClrIntPndStat(SOC_DCAN_1_REGS, msgNum, DCAN_IF2_REG);
dataPtr = (unsigned char*) data;
ConsoleUtilsPrintf("Data received = ");
index1 = (DCANIFMsgCtlStatusGet(SOC_DCAN_1_REGS, DCAN_IF2_REG) &
DCAN_DAT_LEN_CODE_READ);
/* Print the received data bytes on the UART console */
for(index = 0; index < index1; index++)
{
ConsoleUtilsPrintf("%c", *dataPtr++);
}
ConsoleUtilsPutChar('\r');
ConsoleUtilsPutChar('\n');
isrRxFlag = 0;
if(value == index3)
{
/* Disable the receive interrupt of the message object */
CANRxIntDisable(SOC_DCAN_1_REGS, msgNum, DCAN_IF2_REG);
/* Invalidate the receive message object */
CANInValidateMsgObject(SOC_DCAN_1_REGS, msgNum, DCAN_IF2_REG);
}
}
}
}
}
I'm configuring AM335x for 1Mb/sec and the CANId is set to 1. Please suggest what is the issue here?
Regards,