This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

CAN PROTOCOL WITH STM32F107

Hi all.Excuse me for my english.I writed a project for the protocol can with STM32F107VC

I saw the example and modified it. For the Transmission in Loop Back mode, the project is ok

For the RX project there is a problem, because the micrcontroller don't work.

here i copied the two project, the TXproject who is OK and the RX project who isn't OK.

thank you ver much
-------------------------------------
RX PROJECT ISN'T OK
-------------------------------------
include "stm32f10x.h"
#include "GLCD.h"
#include "system_stm32f10x.h"
#include <stdio.h>

typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;
vu32 ret; /* for return of the interrupt handling */
volatile TestStatus TestRx;
ErrorStatus HSEStartUpStatus;

void GPIO_Configuration(void)
{ GPIO_InitTypeDef GPIO_InitStructure;

/* Configure PD.02, PD.03, PD.04 and PD.07 as Output push-pull */ // For STM3210B-LK1 use PD.02 -PC.07 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOD, &GPIO_InitStructure);

/* Configure CAN pin: RX */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOD, &GPIO_InitStructure);

/* Configure CAN pin: TX */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOD, &GPIO_InitStructure);

GPIO_PinRemapConfig(GPIO_Remap2_CAN1, ENABLE ); //PD0-PD1 Osc -> CAN

}

//ϵͳÖжϹÜÀí
void NVIC_Configuration(void)
{ NVIC_InitTypeDef NVIC_InitStructure;

/* Configure the NVIC Preemption Priority Bits */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);

#ifdef VECT_TAB_RAM /* Set the Vector Table base location at 0x20000000 */ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */ /* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif

/* enabling interrupt */
#ifndef STM32F10X_CL NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
#else NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX0_IRQn;
#endif /* STM32F10X_CL*/ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);
}

//ÅäÖÃϵͳʱÖÓ,ʹÄܸ÷ÍâÉèʱÖÓ
void RCC_Configuration(void)
{ SystemInit(); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC |RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |RCC_APB2Periph_ADC1 | RCC_APB2Periph_AFIO |RCC_APB2Periph_SPI1, ENABLE ); //RCC_APB2PeriphClockCmd(RCC_APB2Periph_ALL ,ENABLE ); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4 |RCC_APB1Periph_USART3|RCC_APB1Periph_TIM2 , ENABLE ); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); /* CAN Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
}

void InitDis(void)
{ /* LCD Module init */ GLCD_init(); GLCD_clear(White); GLCD_setTextColor(Blue); GLCD_displayStringLn(Line1, " C A N "); GLCD_displayStringLn(Line2, " Rx"); GLCD_setTextColor(Red);
}

void Can_Config(void) { CAN_InitTypeDef CAN_InitStructure; CAN_FilterInitTypeDef CAN_FilterInitStructure;

/* CAN register init */ CAN_DeInit(CAN1); 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_Mode=CAN_Mode_Normal; CAN_InitStructure.CAN_SJW=CAN_SJW_1tq; CAN_InitStructure.CAN_BS1=CAN_BS1_8tq; CAN_InitStructure.CAN_BS2=CAN_BS2_7tq; CAN_InitStructure.CAN_Prescaler=1; CAN_Init(CAN1,&CAN_InitStructure);

/* CAN filter init */ 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=CAN_FIFO0; CAN_FilterInitStructure.CAN_FilterActivation=ENABLE; CAN_FilterInit(&CAN_FilterInitStructure);

/* CAN FIFO0 message pending interrupt enable */ CAN_ITConfig(CAN1,CAN_IT_FMP0, ENABLE);

}

// Initialization
void Init_All_Periph(void)
{ RCC_Configuration(); InitDis();
// GLCD_Test(); GPIO_Configuration(); NVIC_Configuration(); Can_Config();
}

int main(void)
{ Init_All_Periph();

while(1) {}
}

/*******************************************************************************
* Function Name : USB_LP_CAN_RX0_IRQHandler
* Description : This function handles USB Low Priority or CAN RX0 interrupts
* requests.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
#ifndef STM32F10X_CL
void USB_LP_CAN1_RX0_IRQHandler(void)
#else
void CAN1_RX0_IRQHandler(void)
#endif
{

u8 *vettore_ricevuto; CanRxMsg RxMessage;

GPIO_SetBits(GPIOD, GPIO_Pin_2);

RxMessage.StdId=0x00; RxMessage.ExtId=0x00; RxMessage.IDE=0; RxMessage.DLC=0; RxMessage.FMI=0; RxMessage.Data[0]=0x00; RxMessage.Data[1]=0x00;

CAN_Receive(CAN1,CAN_FIFO0, &RxMessage); vettore_ricevuto=&RxMessage.Data[0];

if( (RxMessage.ExtId==0x1234) && (RxMessage.IDE==CAN_ID_EXT) && (RxMessage.DLC==1) ) { if(vettore_ricevuto[0]==0x42) { GPIO_SetBits(GPIOD, GPIO_Pin_3); } else { GPIO_SetBits(GPIOD, GPIO_Pin_4); }

} else { GPIO_SetBits(GPIOD, GPIO_Pin_7); }

}

THANK YOU FOR THE HELP