Top.Mail.Ru
Уведомления
Очистить все

[Решено] Stm32f4 + CAN + Ethernet

(@dmitrygalich)
New member

Здравствуйте!

STM32F4

Проект: Управление отправкой и приёмом CAN сообщений через Ethernet с помощью браузера.

Проблема: Не работает CAN, как на приём, так и на передачу сообщений.

Судя по флагам, микроконтроллер проходит по всем строчкам инициализации CAN, заходит в функцию отправки сообщений, однако, ничего не отправляет.
Коммутация рабочая.

Подскажите, пожалуйста, как чинить?

Инициализация:

void CAN1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;

/* CAN GPIOs configuration **************************************************/

/* Enable GPIO clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

/* Connect CAN pins */
GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_CAN1);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_CAN1);

/* Configure CAN RX and TX pins */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
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(GPIOB, &GPIO_InitStructure);

/* CAN configuration ********************************************************/
/* Enable CAN clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);

/* 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 Baudrate = 1MBps (CAN clocked at 30 MHz) */
CAN_InitStructure.CAN_BS1 = CAN_BS1_6tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_8tq;
CAN_InitStructure.CAN_Prescaler = 2;
CAN_Init(CAN1, &CAN_InitStructure);

/* CAN filter init */
CAN_FilterInitStructure.CAN_FilterNumber = 0;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_Filter_FIFO0;
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;

CAN_FilterInitStructure.CAN_FilterIdHigh = 0;
CAN_FilterInitStructure.CAN_FilterIdLow = 0;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0;
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0;

CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE);

CAN_FilterInit(&CAN_FilterInitStructure);
}

void NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;

NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

NVIC_InitStructure.NVIC_IRQChannel = CAN1_TX_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}

Функция отправки:

void ASK_1(void)
{
CanTxMsg TxMessage;

// if (CAN_GetITStatus (CAN1, CAN_IT_TME))
// {
// CAN_ClearITPendingBit(CAN1,CAN_IT_TME);

ASK1_DATA0='1';

TxMessage.StdId = 0x101;
TxMessage.RTR = CAN_RTR_DATA;
TxMessage.IDE = CAN_ID_STD;
TxMessage.DLC = 1;
TxMessage.Data[0] = ASK1_DATA0;

//CAN1->TSR&CAN_TSR_TXOK0;
CAN_Transmit(CAN1,&TxMessage);

// }
}

Функция приёма:

void CAN1_RX0_IRQHandler(void)
{
CanRxMsg RxMessage;

if (CAN_GetITStatus (CAN1, CAN_IT_FMP0))
{
CAN_ClearITPendingBit(CAN1,CAN_IT_FMP0);

CAN_Receive(CAN1,CAN_FIFO0, &RxMessage);
CAN_FIFORelease (CAN1,CAN_FIFO0);

READ_DATA0=RxMessage.Data[0];
READ_DATA1=RxMessage.Data[1];
READ_DATA2=RxMessage.Data[2];
READ_DATA3=RxMessage.Data[3];

Can1Flag = ENABLE;
}
}

Цитата
Создатель темы Размещено : 18.02.2017 20:44
Поделиться: