transmit interrupt of CAN works well in loopback mode but vice versa in normal mode
Hi all
I have a project associated with using CAN net work, so I must to use CAN module of stm32f103rdt6
I test transmit interrupt of CAN in loopback mode operating corretly but when I change it into normal mode and change nothing esle in my code, transmit interupt didn't work, even I don't know whether my message is sent or not. This is my code I use to initiate modun CAN
CAN_DeInit(CANx);
CAN_StructInit(&CAN_InitStructure);
/* CAN cell init */
CAN_InitStructure.CAN_TTCM = DISABLE;
CAN_InitStructure.CAN_ABOM = DISABLE;
CAN_InitStructure.CAN_AWUM = DISABLE;
CAN_InitStructure.CAN_NART = DISABLE;
CAN_InitStructure.CAN_RFLM = DISABLE;
CAN_InitStructure.CAN_TXFP = DISABLE;
// CAN_InitStructure.CAN_TXFP = ENABLE;
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
//CAN_InitStructure.CAN_Mode=CAN_Mode_LoopBack;
/* CAN Baudrate = 1MBps*/
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_3tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_5tq;
CAN_InitStructure.CAN_Prescaler = 4;
CAN_Init(CANx, &CAN_InitStructure);
/* CAN filter init */
CAN_FilterInitStructure.CAN_FilterNumber = 0;
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000;
CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 0;
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
/* Transmit */
TxMessage.StdId = 00;
TxMessage.ExtId = 0x00;
TxMessage.RTR = CAN_RTR_DATA;
TxMessage.IDE = CAN_ID_STD;
TxMessage.DLC = 8;// em can gui 4 byte 1 lan
TxMessage.Data[0]=0;
TxMessage.Data[1]=0;
TxMessage.Data[2]=0;
TxMessage.Data[4]=0;
TxMessage.Data[5]=0;
TxMessage.Data[6]=0;
TxMessage.Data[7]=0;
and this is my nvic configuration
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//nvic for can
//NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel =USB_HP_CAN1_TX_IRQn ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
and this is my interrupt function
void USB_HP_CAN1_TX_IRQHandler(void)
{
//CTR_HP();
ttnghiabk_senduart("ok.da thanh cong");
GPIO_WriteBit(GPIOB, GPIO_Pin_12, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_13)));
GPIO_WriteBit(GPIOB, GPIO_Pin_13, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_13)));
CAN_ClearITPendingBit(CAN1,CAN_IT_TME);
}
I just change " CAN_InitStructure.CAN_Mode=CAN_Mode_LoopBack;"into
"CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;". It's incredible, interrupt operation didn't work, I don't understand why???????
Can you show me reason. Thanks indeed