hi,
I want to use DCAN1 module, and set it to Loop Back Mode, Message box1 is for sending data and Message box2 is for receiving data,
but it can not receive data, canIsRxMessageArrived() always return 0.
I have a question at CANRAM init code :
SYS_Ptr->MINITGCR_UN.MINITGCR_UL = 0xA;
SYS_Ptr->MSINENA_UL = MEM_CH_DCANRAM;
while(SYS_Ptr->MINISTAT_UL == 0);
SYS_Ptr->MINITGCR_UN.MINITGCR_UL = 0x5;
what is the macro MEM_CH_DCANRAM 's value ? I can't find in datasheet.
I modify the GenCode canInit() for TEST mode,
void canInit(void)
{
/* USER CODE BEGIN (4) */
/* USER CODE END */
/** @b Initialize @b CAN1: */
/** - Setup control register
* - Disable automatic wakeup on bus activity
* - Local power down mode disabled
* - Disable DMA request lines
* - Enable global Interrupt Line 0 and 1
* - Disable debug mode
* - Release from software reset
* - Disable parity and ECC
* - Enable/Disable auto bus on timer
* - Setup message completion before entering debug state
* - Setup normal operation mode
* - Request write access to the configuration registers
* - Setup automatic retransmission of messages
* - Disable error interrupts
* - Disable status interrupts
* - Enter initialization mode
*/
/*set to TEST mode*/
canREG1->CTL = 0x00000000U
| 0x00000000U
| 0x000114C3U; /* 0x00021443U;*/
/** - Clear all pending error flags and reset current status */
canREG1->ES = 0x31FU; /*canREG1->ES;*/
/** - Assign interrupt level for messages */
canREG1->INTMUXx[0U] = 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U;
canREG1->INTMUXx[1U] = 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U
| 0x00000000U;
/** - Setup auto bus on timer period */
canREG1->ABOTR = 0U;
/** - Initialize message 1
* - Wait until IF1 is ready for use
* - Set message mask
* - Set message control word
* - Set message arbitration
* - Set IF1 control byte
* - Set IF1 message number
*/
while ((((canREG1->IF1CMD & 0x0000FF00U) >> 8U) & 0x00000080U) == 0x00000080U)
{
} /* Wait */
canREG1->IF1MSK = 0xC0000000U | ((0x000007FFU & 0x1FFFFFFFU) << 0U);
canREG1->IF1ARB = 0x80000000U | 0x40000000U | 0x20000000U | ((1U & 0x1FFFFFFFU) << 0U);
canREG1->IF1MCTL = 0x00001080U | 0x00000000U | 8U;
canREG1->IF1CMD = (canREG1->IF1CMD & 0xFF00FFFFU) | (0xF8U << 16U);
canREG1->IF1CMD = (canREG1->IF1CMD & 0xFFFFFF00U) | (1U);
/** - Initialize message 2
* - Wait until IF2 is ready for use
* - Set message mask
* - Set message control word
* - Set message arbitration
* - Set IF2 control byte
* - Set IF2 message number
*/
while ((((canREG1->IF2CMD & 0x0000FF00U) >> 8U) & 0x00000080U) == 0x00000080U)
{
} /* Wait */
canREG1->IF2MSK = 0xC0000000U | ((0x000007FFU & 0x1FFFFFFFU) << 0U);
canREG1->IF2ARB = 0x80000000U | 0x40000000U | 0x00000000U | ((2U & 0x1FFFFFFFU) << 0U);
canREG1->IF2MCTL = 0x00001080U | 0x00000000U | 8U;
canREG1->IF2CMD = (canREG1->IF2CMD & 0xFF00FFFFU) | (0xF8U << 16U);
canREG1->IF2CMD = (canREG1->IF2CMD & 0xFFFFFF00U) | (2U);
/** - Setup IF1 for data transmission
* - Wait until IF1 is ready for use
* - Set IF1 control byte
*/
while ((((canREG1->IF1CMD & 0x0000FF00U) >> 8U) & 0x00000080U) == 0x00000080U)
{
} /* Wait */
canREG1->IF1CMD = (canREG1->IF1CMD & 0xFF00FFFFU) | (0x87U << 16U);
/** - Setup IF2 for reading data
* - Wait until IF1 is ready for use
* - Set IF1 control byte
*/
while ((((canREG1->IF2CMD & 0x0000FF00U) >> 8U) & 0x00000080U) == 0x00000080U)
{
} /* Wait */
canREG1->IF2CMD = (canREG1->IF2CMD & 0xFF00FFFFU) | (0x17U << 16U);
/** - Setup bit timing
* - Setup baud rate prescaler extension
* - Setup TSeg2
* - Setup TSeg1
* - Setup sample jump width
* - Setup baud rate prescaler
*/
canREG1->BTR = (0U << 16U) |
((2U - 1U) << 12U) |
(((3U + 2U) - 1U) << 8U) |
((2U - 1U) << 6U) |
19U;
/** - Setup TX pin to functional output */
/* canREG1->TIOC = 0x0000004CU; */
/** - Setup RX pin to functional input */
/* canREG1->RIOC = 0x00000048U; */
/** - Setup loop back mode */
canREG1->TEST = 0x00000210U;
/** - Leave configuration and initialization mode */
canREG1->CTL &= ~(0x00000041U);
/* USER CODE BEGIN (5) */
/* USER CODE END */
}
/* ***************** main code ******************/
{
canInit(); /* can1*/
/* transmit on can1 */
canTransmit(canREG1, canMESSAGE_BOX1, tx_data);
/*... wait until message receive on can1 */
while(!canIsRxMessageArrived(canREG1, canMESSAGE_BOX2));
canGetData(canREG1, canMESSAGE_BOX1, rx_data); /* receive on can1 */
}
I can`t find please help me,