I'm having pretty much the same trouble. It seems to init ok (checked the returned status from CAN_Init()), but any messages that I want to send via CAN_Transmit are pending, until all 3 mailbox holes are filled, then I get CAN_NO_MB of course. I monitored the CAN pins with a CRO, and they don't budge. Also, the flags EWG, EPV and BOF seem to be set, which doesn't sound right. Have you made any progress?
yesterday, i was able to initialize can on stm32f103 rZ (100pin) (EVAL Board) by changing some lines in the CAN_Init() function. the Loopback Mode was working great, but i want to communicate with another mcu(same board, same mcu) via can bus. i'm currently using PD0/PD1 for communication. clock, nvic ( and gpio settings should be correct. after initialization i try to send a msg on bus and the other board should receive it, but my sending function timeouts in the state TX_PENDING. :-W does anyone has an idea, what i have done wrong, or what i can do to make this working. pls help me, my project has to finished in a few weeks and i'm totally frustrated! :-[ ciao mario[ This message was edited by: mario.noessing on 14-01-2009 23:08 ]
attachment includes can communication projects between two STM32 EVAL boards. One board is in Silent and the other in LoopBack mode. The only step you have to make to send / receive in Normal mode, is to configure one as LoopBack and on as Normale. Then send an CAN_INIT Message (11 recessive bits) to the bus (REMOTE) with the board in LoopBack to initialize communication on the ''Normal mode'' - board. After this step, switch the ''Loop Back'' - Board into Normal mode, and both boards are able to send/receive. cheers, Mario
CAN with PLL works (HSE feeds PLL), below is the code i use to ini clock
Code:
/* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON); /* Wait till HSE is ready */ while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET) { } /* Select HSE as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE); /* Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp(); if(HSEStartUpStatus == SUCCESS) { /* Enable Prefetch Buffer */ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); /* Flash 0 wait state */ FLASH_SetLatency(FLASH_Latency_1); /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK */ RCC_PCLK1Config(RCC_HCLK_Div1); /* PLLCLK = 8MHz * 3 = 24 MHz */ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_3); /* Enable PLL */ RCC_PLLCmd(ENABLE); /* Wait till PLL is ready */ while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); /* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x08); }//if as you can see, i configure for 24mhz system clock. here is my CAN clock config:
Code:
CAN_InitStructure.CAN_SJW=CAN_SJW_1tq; CAN_InitStructure.CAN_BS1=CAN_BS1_9tq; CAN_InitStructure.CAN_BS2=CAN_BS2_2tq; CAN_InitStructure.CAN_Prescaler=4; These two clock configs seem to give 1Mbps speed. I am almost certain as i have a device that presumably operates at 1Mbps, and it acknowleges the messages i send from the stm32 good luck
my CAN is working with HSE as system clock, but not with the PLL as system clock! I am using an external crystal of 8MHz and a PLL multiplier of 8. Since the CAN is attached to AHB1, which uses a divider of 2, I multiplied the prescaler value by 8/2=4. Is my calculation correct? Has anybody used the CAN with internal PLL? Thank you for an answer! Regards, Michael