stm32f042 + can bus
Jaroslav Buchta
jaroslav.buchta na hascomp.cz
Čtvrtek Listopad 10 18:08:55 CET 2016
Zkuste CAN_ABOM a CAN_NART nastavit na ENABLE.
Neni sbernice defaultne v neklidovem stavu, treba prehozene H a L nebo
zkrat? Radic to detekuje a po nejakych stech cyklech se uvede do
neprovozniho stavu (ABOM resi aspon automatickou reinicializaci po
nejakem case klidu na sbernici)
Dne 10.11.2016 v 13:38 tomas mainzer napsal(a):
> Dobry den,
> nemate nekdo prosim funkcni priklad pro STM32F042 a can bus?
> Vychazim z prikladu pro STM32f072 - ake nedari se mi ani odeslat CAN
> packet - uz jsem vyzkousel priklady (puvodne pro STM32F072) pro SPL
> knihovny (to prekladam v embitz) i pro CubeMX (to prekladam v Atollic
> TRUEstudiu) a nedokazu prijit na to kde je zakopan pes.
> Uvitam jakekoliv tipy.
>
> Nize je relevantni vysek programu pro SPL (CAN je na pinech PA11,PA12):
>
>
> GPIO_InitTypeDef GPIO_InitStructure;
> NVIC_InitTypeDef NVIC_InitStructure;
> CAN_InitTypeDef CAN_InitStructure;
> CAN_FilterInitTypeDef CAN_FilterInitStructure;
>
>
> /* CAN GPIOs configuration
> **************************************************/
>
> /* Enable GPIO clock */
> //RCC_AHBPeriphClockCmd(CAN_GPIO_CLK, ENABLE);
> RCC_AHBPeriphClockCmd(RCC_APB1Periph_CAN, ENABLE);
> RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
>
> /* Connect CAN pins to AF7 */
> GPIO_PinAFConfig(CAN_GPIO_PORT, CAN_RX_SOURCE, CAN_AF_PORT);
> GPIO_PinAFConfig(CAN_GPIO_PORT, CAN_TX_SOURCE, CAN_AF_PORT);
>
> /* Configure CAN RX and TX pins */
> GPIO_InitStructure.GPIO_Pin = CAN_RX_PIN | CAN_TX_PIN;
> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
> GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
> GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
> GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
> GPIO_Init(CAN_GPIO_PORT, &GPIO_InitStructure);
>
> /* CAN NVIC configuration
> **************************************************/
> NVIC_InitStructure.NVIC_IRQChannel = CEC_CAN_IRQn;
> NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
> NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
> NVIC_Init(&NVIC_InitStructure);
>
> /* CAN configuration
> ********************************************************/
> /* Enable CAN clock */
> RCC_APB1PeriphClockCmd(CAN_CLK, ENABLE);
>
> /* CAN register init */
> CAN_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;//ENABLE;
> CAN_InitStructure.CAN_TXFP = DISABLE;//ENABLE;
> CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
> CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
>
> /* CAN Baudrate = 1MBps (CAN clocked at 36 MHz) */
> CAN_InitStructure.CAN_BS1 = CAN_BS1_9tq;
> CAN_InitStructure.CAN_BS2 = CAN_BS2_8tq;
> CAN_InitStructure.CAN_Prescaler = 2;
> CAN_Init(CANx, &CAN_InitStructure);
>
> /* CAN filter init "FIFO0" */
> CAN_FilterInitStructure.CAN_FilterNumber = 0;
> CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdList;
> CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
> CAN_FilterInitStructure.CAN_FilterIdHigh = 0x6420;
> CAN_FilterInitStructure.CAN_FilterIdLow = 0x2461;
> 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 Structure preparation */
> TxMessage.StdId = 0x321;
> TxMessage.ExtId = 0x00;
> TxMessage.RTR = CAN_RTR_DATA;
> TxMessage.IDE = CAN_ID_STD;
> TxMessage.DLC = 1;
>
> /* Enable FIFO 0 full Interrupt */
> //CAN_ITConfig(CANx, CAN_IT_FF0, ENABLE);
> CAN_ITConfig(CANx, CAN_IT_FMP0, ENABLE);
>
> ...
>
> TxMessage.Data[0] = (uint8_t)(tick);
> CAN_Transmit(CANx, &TxMessage);
>
>
> Dekuji. TM.
>
>
> _______________________________________________
> HW-list mailing list - sponsored by www.HW.cz
> Hw-list na list.hw.cz
> http://list.hw.cz/mailman/listinfo/hw-list
------------- další část ---------------
HTML příloha byla odstraněna...
URL: <http://list.hw.cz/pipermail/hw-list/attachments/20161110/445ee927/attachment.html>
Další informace o konferenci Hw-list