Tool/software:
Hello,
I'm trying to implement a DCAN internal analog loopback test based on the configuration described in the Safety Manual and TRM (Technical Reference Manual).
The problem is, the SDL API documentation does not define or mention Loopback Mode at all, despite claiming that SL_SelfTest_CAN can perform an analog loopback test. Additionally, the documentation provided is poorly written and doesn't explain the configuration process for internal loopback mode thoroughly, leaving many gaps in the understanding of how to properly configure the system.
According to the documentation, I understand that the DCAN needs to be in Test Mode and the Internal Loopback Mode must be activated by setting the LBack bit in the Test Register.
However, while I can confirm that data is being sent (I've sniffed the TX line), the issue I'm encountering is that the RX buffer remains empty, even though the DCAN is configured for loopback mode.
Here’s the current configuration for the Control and Test registers after enabling Test Mode and Internal Loopback:
- DCAN2->Ctrl =
0x00032882
- DCAN2->Test =
0x00000090
- DCAN2->ErrStat =
0x00000008
- DCAN2->IoCtrlTx =
0x0004000F
- DCAN2->IoCtrlRx =
0x00040009
Here is my test function:
SdlRun_retval_e SdlRun_can_init_loopback() { SdlRun_retval_e retVal = SDL_RUN_EINVAL; boolean status = FALSE; bool canStatus; const uint8_t txBuf[8u] = {0x00u, 0xFFu, 0x0Fu, 0xF0u, 0x33u, 0xCCu, 0x55u, 0xAAu}; uint8_t rxBuf[8u]; uint8_t rxLen; /* Enable CAN test mode */ canREG2->CTL |= (uint32_t)(1U << 7); /* Activate Loopback Mode */ canREG2->TEST |= (uint32)(1U << 4); /* Send CAN message */ canStatus = CAN_boWrite(CAN_HDL_LP_TX, txBuf); if(canStatus != TRUE) { retVal = SDL_RUN_EINTERNAL; } /* Send messages from TX buffer */ CAN_Tx_Job(); /* Periodic CAN read */ canStatus = FALSE; do { /* Receive CAN message */ canStatus = CAN_boRead(CAN_HDL_LP_RX, rxBuf, &rxLen); } while (canStatus != TRUE); /* Compare data */ status = memcmp((void*)txBuf, (void*)rxBuf, 8u); if (status != 0) { retVal = SDL_RUN_EDATA; // break; } /* Disable CAN test mode */ canREG2->CTL &= ~(uint32_t)(1U << 7); /* Deactivate Loopback Mode */ canREG2->TEST &= ~(uint32)(1U << 4); /* Test passed */ retVal = SDL_RUN_SUCCESS; return retVal; }
Did I configure the DCAN correctly for internal loopback mode?
Why is the RX buffer empty after sending data in loopback mode?
Thanks & regards,
Ilija