2012-04-05 07:57 PM
Hi all
I have a project associated with using CAN net work, so I must to use CAN module of stm32f103rdt6I 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 CANCAN_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 configurationNVIC_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 functionvoid 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 indeed2012-04-09 11:42 PM
2012-04-10 01:44 AM
Seems obvious, but since you didn't mention it:
- did you check status bits in both cases?- how about trying some example code? They mostly suck, but usually they do good as a working starting point.2012-04-10 08:14 PM
oh, of couse I use example source from ST's library. I just buitlt it from there
I down many right code about CAN from forum and an other source to check but I don't realize the diffirence. so that I said''It's incredible''. hix. Can you recommend the detail more2012-04-10 11:43 PM
Of course! :p Now let me repeat:
Seems obvious, but since you didn't mention it:
- did you check status bits in both cases?2012-04-11 05:05 AM
Another problem here is that a whole bunch of code is missing. I don't see any clock or pin configuration.
2012-04-12 08:17 AM
2012-10-17 01:23 AM
2012-10-17 06:50 AM
I'm using CAN on F2 devices.
The F1 board I have access to (STM3210E-EVAL) has CAN on PB8/9. I was able to generate CANTX traffic with thisCanTxMsg TxMessage;
CanRxMsg RxMessage;
void CAN_setup(void)
{
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
#if 0
/* Configure CAN1 RX pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure CAN1 TX pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
#endif
#if 1 // STM3210E-EVAL
/* Configure CAN1 RX pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure CAN1 TX pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinRemapConfig(GPIO_Remap1_CAN1 , ENABLE); // PB.8 & PB.9
#endif
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);//Enable the clock for CAN
CAN_DeInit(CAN1);
/* Struct init*/
CAN_StructInit(&CAN_InitStructure);
/* Configure CAN1 **************************************************/
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 = ENABLE; // DISABLE;
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
#if 0
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 = 32; // 125kbps
#else
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_6tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_8tq;
CAN_InitStructure.CAN_Prescaler = 36000000 / (15 * 125000); // quanta by baudrate
#endif
CAN_Init(CAN1, &CAN_InitStructure);
/* CAN1 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 = 0x321 <<
5
;
CAN_FilterInitStructure.CAN_FilterIdLow
=
0x0000
;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh
=
0xFFE0
;
CAN_FilterInitStructure.CAN_FilterMaskIdLow
=
0x0000
;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment
=
0
;
CAN_FilterInitStructure.CAN_FilterActivation
=
ENABLE
;
CAN_FilterInit(&CAN_FilterInitStructure);
/* Transmit INITIALIZATION*/
TxMessage.IDE
=
CAN_ID_STD
;
TxMessage.DLC
=
6
;
TxMessage.StdId
=
0x321
;
TxMessage.ExtId
=
0
;
TxMessage.RTR
=
CAN_RTR_DATA
;
TxMessage.Data[0] = 0xCA;
TxMessage.Data[1] = 0xFE;
TxMessage.Data[7] = 0x55;
TxMessage.Data[8] = 0xAA;
}
int main(void)
{
volatile int i;
uint8_t TransmitMailbox;
uint32_t count;
CAN_setup();
count
=
0
;
while(1)
{
TxMessage.Data[2] = (uint8_t)((count >> 0) & 0xFF);
TxMessage.Data[3] = (uint8_t)((count >> 8) & 0xFF);
TxMessage.Data[4] = (uint8_t)((count >> 16) & 0xFF);
TxMessage.Data[5] = (uint8_t)((count >> 24) & 0xFF);
count++;
TransmitMailbox = CAN_Transmit(CAN1, &TxMessage);
i = 0;
while((CAN_TransmitStatus(CAN1, TransmitMailbox) != CANTXOK) && (i < 0xFFFFFF))
{
i++;
}
}
}
2016-09-14 05:37 AM
Hello All,
I have been using CAN Tx Rx with polling and timeout for a long time but now I want to do it with interrupts. I am usnig an STM32f334c8t7 processor which is interfraced to Microchip's 2562 CAN transciever. I can enable interrrupt in the IER and some CAN messages are sent (6 to be precise) before it all freezes. I can actually not make up the sequence for transmitting via interrupts. When should i enable the TME interrupt when and what should be in the TX Complete callback function. Is it necessary to implement it or not? can somebody please draw a basic outline of the sequence. PS: I am using MX Cube for code generation and i think somehow this HAL locking unlocking is messing it all up. I want to quickly fill all the 3 mail boxes one by one and then they get transmitted and i get the interrupt upon which i would transmit even more messages and so on.
Thanks