cancel
Showing results for 
Search instead for 
Did you mean: 

CAN interrupts does not work

batist_2008
Associate II
Posted on May 08, 2012 at 10:13

hello everyone!

Help me, please, to find where is a bug in my programm for CAN slave. I have two boards. One is evaluation sk-mstm32f It sends requests. And the other board is my own board on stm32f103, which have to receive messadges from the first one. The problem is, that in Keil Peripherals CAN Receive I see, that the board stm32f103 receives that message, that stm32f107 sends. But interrupts does not work. And when there is transmition when I stop debugging I see, that I am at stop at string 324 of file startup_stm32f10x_hd.s. What is the problemm and where are in my project/projects bug/bugs? Here is the code for receiver on stm32f

#include ''stm32f10x.h'' 
CanTxMsg TxMessage; 
CanRxMsg RxMessage; 
uint8_t CAN_TxRdy; 
uint8_t CAN_RxRdy; 
uint8_t val_Rx; 
/*============================================================================*/ 
void Init_CLK (void) 
{ 
RCC_ClocksTypeDef RCC_Clocks; 
RCC_GetClocksFreq(&RCC_Clocks); 
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE); 
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE); 
SysTick_CLKSourceConfig( SysTick_CLKSource_HCLK ); 
} 
/*=============================================================================*/ 
void Init_GPIO_CAN (void) 
{ 
GPIO_InitTypeDef GPIO_InitStructure; 
//Tx 
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12; //PA2=Tx; 
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; // Alt Function - Push Pull 
GPIO_Init(GPIOA, &GPIO_InitStructure); 
//Rx 
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_11; //PA3=Rx; 
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // 
GPIO_Init(GPIOA, &GPIO_InitStructure); 
// 
} 
/*=========================================================================*/ 
void Init_CAN (void) 
{ 
CAN_InitTypeDef CAN_InitStructure; 
CAN_FilterInitTypeDef CAN_FilterInitStructure; 
CAN_DBGFreeze(CAN1,DISABLE); 
CAN_DeInit(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; 
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal; 
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq; 
CAN_InitStructure.CAN_BS1 = CAN_BS1_16tq; 
CAN_InitStructure.CAN_BS2 = CAN_BS2_8tq; 
CAN_InitStructure.CAN_Prescaler =2; 
CAN_DBGFreeze(CAN1,DISABLE); 
CAN_Init(CAN1, &CAN_InitStructure); 
//Oeeuo? aa?oiaai CAN 
CAN_FilterInitStructure.CAN_FilterNumber = 1; 
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); 
/* 
//CAN_FilterInitStructure.CAN_FilterIdHigh =0x2460; 
CAN_FilterInitStructure.CAN_FilterNumber = 15; 
CAN_FilterInit(&CAN_FilterInitStructure); 
*/ 
} 
/*======================================================================*/ 
void NVIC_CAN_Configuration(void) 
{ 
NVIC_InitTypeDef NVIC_InitStructure; 
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); 
NVIC_InitStructure.NVIC_IRQChannel=USB_LP_CAN1_RX0_IRQn;//|USB_HP_CAN1_TX_IRQn; 
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0; 
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0; 
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 
NVIC_Init(&NVIC_InitStructure); 
} 
/*=============================================================================*/ 
void USB_HP_CAN1_TX_IRQHandler (void) 
{ 
if (CAN_GetITStatus(CAN1,CAN_IT_TME)) 
{ // request completed mbx 0 
CAN_ClearITPendingBit(CAN1,CAN_IT_TME); 
CAN_TxRdy++; 
} 
} 
/*================================================================================*/ 
void USB_LP_CAN1_RX_IRQHandler (void) 
{ 
if (CAN_GetITStatus(CAN1,CAN_IT_FMP0)) 
{ // message pending ? 
CAN_Receive(CAN1,0,&RxMessage); // read the message 
CAN_RxRdy++; // set receive flag 
} 
} 
/*==========================================================================*/ 
int main (void) 
{ 
__disable_irq (); 
Init_CLK(); 
NVIC_CAN_Configuration(); 
Init_GPIO_CAN(); 
Init_CAN(); 
CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE); 
CAN_ITConfig(CAN1, CAN_IT_FF0, ENABLE); 
CAN_ITConfig(CAN1, CAN_IT_FOV0, ENABLE); 
__enable_irq (); 
TxMessage.StdId = 0x321; 
TxMessage.ExtId = 0x01; 
TxMessage.RTR = CAN_RTR_DATA; 
TxMessage.IDE = CAN_ID_STD; 
TxMessage.DLC = 1; 
while (1) {} 
} 

2 REPLIES 2
Posted on May 08, 2012 at 14:14

void USB_LP_CAN1_RX0_IRQHandler (void)

{ ...

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
batist_2008
Associate II
Posted on May 10, 2012 at 08:03

Oh!!!!! Thanks a lot!!!!