2019-10-08 06:52 AM
Hello everyone,
I want to contact STM32F103VC and STM32F407 with canbus protocol without transceiver.
I set baudrate 60kHz. but I can not send or receive data. Can you hel please ?
Thank you.
2019-10-08 11:15 PM
void InitCanBus(void){
CAN_InitTypeDef CanInitStruct;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
InitGPIOForCAN();
CAN_DeInit(CAN1);
//CAN_StructInit(&CanInitStruct);
CanInitStruct.CAN_ABOM = DISABLE;
CanInitStruct.CAN_AWUM = DISABLE;
CanInitStruct.CAN_BS1 = CAN_BS1_5tq;
CanInitStruct.CAN_BS2 = CAN_BS2_4tq;
CanInitStruct.CAN_Mode = CAN_Mode_Normal;
CanInitStruct.CAN_NART = DISABLE;
CanInitStruct.CAN_Prescaler = 58;
CanInitStruct.CAN_RFLM = DISABLE;
CanInitStruct.CAN_SJW = CAN_SJW_1tq;
CanInitStruct.CAN_TTCM = DISABLE;
CanInitStruct.CAN_TXFP = DISABLE;
if(CAN_Init(CAN1, &CanInitStruct))
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=CAN_FIFO1;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_ITConfig(CAN1, CAN_IT_FMP1, ENABLE);
CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX1_IRQn;
NVIC_InitStructure.NVIC_IRQChannel = USB_HP_CAN1_TX_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_EnableIRQ(CAN1_RX1_IRQn);
// CAN_OperatingModeRequest(CAN1, 1);
}
This is my configure function for CANBUS
2019-10-08 11:18 PM
void InitGPIOForCAN(void){
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); /* NOTE: GPIOA, GPIOB peripheral clock enable */
GPIO_InitStructure.GPIO_Pin = CAN_RX;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; /* NOTE: GPIO hizi 50 Mhz */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; /* NOTE: Cikis modu, push pull */
GPIO_Init(CAN_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = CAN_TX;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; /* NOTE: GPIO hizi 50 Mhz */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; /* NOTE: Cikis modu, push pull */
GPIO_Init(CAN_PORT, &GPIO_InitStructure);
//GPIO_PinRemapConfig(GPIO_Remap1_CAN1, ENABLE);
//GPIO_PinRemapConfig(GPIO_Remap2_CAN1, ENABLE);
}
and, this is my pin configure function
2019-10-09 06:32 AM
you think, this configuration is wrong for stm32f103 ?
2019-10-09 06:43 AM
you think, is configure wrong for STM32F103?
2019-10-09 07:18 AM
you think, Is configure wrong for STM32F103?
2019-10-09 08:14 AM
What pins?
I'd hazard this isn't clocking at 60 KHz. If the APB1 clock is 36 MHz, perhaps closer to 62 KHz
Like I said, you need to be talking to some other device on the bus, and it needs to respond.
I'd usually start by having CAN1 talk to CAN2 on the same system
I posted some CAN demo code for the F2 and F4 using the SPL to the forum many years back.
2019-10-09 08:36 AM
Pins are pa11 and pa12. mcu's frequency is 72 mhz. Bus frequency iş 36 mhz. And ı set canbus baudrate 50 khz. Stm32f4 can talk stm32f7. But stm32f103 cant talk. It can not send data.
2019-10-10 10:47 PM
Hello again.
I try to do this on cubemx. Now, I can send data but I can not receive data. I compare F4 and F1. And I saw that F4's rx pin mode: "alternate function push pul" but f1's rx pin mode :"Input mode". When I cahange it as alternate, Canbus does not init. so I think does not f1 work without tranciever. What do you think about that ?