2016-05-21 09:17 AM
Hi,
I m using STM32F103 Nucleo board and keil compiler. I m using HAL_CAN stack. I configured filter in mask mode and set to receive all messages. Mode : Loopback mode speed : 250 kbps ID : standard I m problem like, if i could sent the message only once only. I m sending the message in while loop continously then also it is going once. Following is my code here is code.void send_msg(void)
{
hcan.pTxMsg = &txmsg;
hcan.pRxMsg = &rxmsg;
txmsg.StdId = 0x123;
txmsg.DLC = 5;
txmsg.Data[0] = 'H';
txmsg.Data[1] = 'e';
txmsg.Data[2] = 'L';
txmsg.Data[3] = 'L';
txmsg.Data[4] = 'o';
txmsg.IDE = 0;
txmsg.RTR = 0;
HAL_CAN_Transmit(&hcan,2000);
}
void MX_CAN_Init(void)
{
__CAN_CLK_ENABLE();
hcan.pTxMsg = &txmsg;
hcan.pRxMsg = &rxmsg;
hcan.Instance = CAN1;
hcan.Init.Prescaler = 16; //250 kbps baud rate.
hcan.Init.Mode = CAN_MODE_LOOPBACK;
hcan.Init.SJW = CAN_SJW_1TQ;
hcan.Init.BS1 = CAN_BS1_5TQ;
hcan.Init.BS2 = CAN_BS2_2TQ;
hcan.Init.TTCM = DISABLE;
hcan.Init.ABOM = DISABLE;
hcan.Init.AWUM = DISABLE;
hcan.Init.NART = DISABLE;
hcan.Init.RFLM = DISABLE;
hcan.Init.TXFP = DISABLE;
HAL_CAN_Init(&hcan);
CAN_FilterStruct.FilterIdHigh = 0x0000; /* Upper 16bit filter ID */
CAN_FilterStruct.FilterIdLow = 0x0000; /* Filter lower 16bit ID */
CAN_FilterStruct.FilterMaskIdHigh = 0x0000; /* Upper 16bit filter mask */
CAN_FilterStruct.FilterMaskIdLow = 0x0000; /* Lower 16bit filter mask */
CAN_FilterStruct.FilterFIFOAssignment = CAN_FILTER_FIFO0; /* Which FIFO will be assigned to filter */ ///Need to check whether FIFOx is assigned to respective RXx.
CAN_FilterStruct.FilterNumber = 0;
CAN_FilterStruct.FilterMode = CAN_FILTERMODE_IDMASK; /* Identifier mask mode */
CAN_FilterStruct.FilterScale = CAN_FILTERSCALE_32BIT; /* 32bit ID filter */
CAN_FilterStruct.FilterActivation = ENABLE; /* Enable this filter */
CAN_FilterStruct.BankNumber = 14; /* Start slave bank filter (?) */
HAL_CAN_ConfigFilter(&hcan, &CAN_FilterStruct); /* Initialize filter */
HAL_NVIC_SetPriority(CAN1_RX0_IRQn, 1, 1); /* Set CAN1 Rx interrupt priority to 1-1 */
HAL_NVIC_EnableIRQ(CAN1_RX0_IRQn); /* Enable CAN1 Rx Interrupt */
__HAL_CAN_ENABLE_IT(&hcan, CAN_IT_FMP0); /* Enable 'message pending in FIFO0' interrupt */
}
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_CAN_Init();
MX_USART1_UART_Init();
HAL_UART_Transmit(&huart1,''_Init'',5,1000);
GPIOA->ODR = 0x00000000;
send_msg();
while (1)
{
if(Sig_CAN_Status==1)
{
HAL_UART_Transmit(&huart1,''_RX0:'',4,1000);
GPIOA->ODR = 0x00000020;
Sig_CAN_Status = 0;
HAL_UART_Transmit(&huart1,&hcan.pRxMsg->Data[0],5,1000);
delay();
send_msg();
Sig_CAN_Status = 0;
}
else if(CAN_FLAG_FOV0==1)
{
HAL_UART_Transmit(&huart1,''_OverFlow'',9,1000);
}
}
}
#bxcan #nucleo #stm32f302
2016-05-23 08:29 AM
Hi hobb.epy,
I see that it is a normal behavior since you have called transmit function in pooling [send_msg()] only one time in the main(). I recommend that you run the CAN_Networking example under one of STM32CubeFx packages. This example shows how to configure the CAN peripheral to send and receive CAN frames in normal mode. -Hannibal-2016-05-23 09:10 AM
Hi,
I called that Send_msg function contimous in the loop.When Rx handler receives the message there i m setting Sig_CAN_Status as 1. And again i m sending it. So it is continous.