请问STM32F107 RT-Thread 下CAN如何配置才能进接收中断?
请问STM32F107 RT-Thread 下CAN如何配置才能进接收中断?目前配置如下:
static void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
//NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
/* Enable the CAN Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = CAN2_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_Init(&NVIC_InitStructure);
}
static void RCC_Configuration(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1| RCC_APB1Periph_CAN2, ENABLE);
}
static void GPIO_Configuration(void)
{
GPIO_InitTypeDefGPIO_InitStructure;
/* CAN1 初始化 */
GPIO_InitStructure.GPIO_Pin = CAN1_Tx_Pin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(CAN1_GPIO, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = CAN1_Rx_Pin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(CAN1_GPIO, &GPIO_InitStructure);
/* 如果定义了映射标记,则重映射 */
#if CAN1_REMAP_FLAG
GPIO_PinRemapConfig(CAN1_REMAP_CONFIG , ENABLE);
#endif
/* CAN2 初始化 */
GPIO_InitStructure.GPIO_Pin = CAN2_Tx_Pin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(CAN2_GPIO, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = CAN2_Rx_Pin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(CAN2_GPIO, &GPIO_InitStructure);
/* 如果定义了映射标记,则重映射 */
#if CAN2_REMAP_FLAG
GPIO_PinRemapConfig(CAN2_REMAP_CONFIG , ENABLE);
#endif
}
void rt_hw_can_init(void)
{
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDefCAN_FilterInitStructure;
GPIO_Configuration();
NVIC_Configuration();
RCC_Configuration();
/* CAN1 cell init */
CAN_DeInit(CAN1);
CAN_StructInit(&CAN_InitStructure);
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 = ENABLE;
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_11tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_6tq;
CAN_InitStructure.CAN_Prescaler = 100; //200: 10K ; 100 - 20K
/* Initializes the CAN1 */
CAN_Init(CAN1, &CAN_InitStructure);
/* IT Configuration for CAN1 */
CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
/* CAN2 cell init */
CAN_DeInit(CAN2);
CAN_StructInit(&CAN_InitStructure);
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 = ENABLE;
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_11tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_6tq;
CAN_InitStructure.CAN_Prescaler = 100; //200: 10K ; 100 - 20K
/* Initializes the CAN2 */
CAN_Init(CAN2, &CAN_InitStructure);
/* IT Configuration for CAN1 */
CAN_ITConfig(CAN2, CAN_IT_FMP0, ENABLE);
/* 初始化过滤器 */
CAN_FilterInitStructure.CAN_FilterNumber = 14;
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);
/* 发送消息清空 */
m_TxMessage.StdId = 0x00;
m_TxMessage.ExtId = 0x00;
m_TxMessage.RTR = CAN_RTR_DATA;
m_TxMessage.IDE = CAN_ID_STD;
m_TxMessage.DLC = 1;//一次发送的数据长度
/* 注_册CAN1设备 */
can1_device.type = RT_Device_Class_CAN;
can1_device.init = RT_NULL;
can1_device.open = RT_NULL;
can1_device.close = RT_NULL;
can1_device.read = rt_hw_can_read;
can1_device.write = rt_hw_can_write;
can1_device.control = rt_hw_can_control;
can1_device.private = RT_NULL;
rt_device_register(&can1_device, "can1", RT_DEVICE_FLAG_RDWR);
/* 注_册CAN2设备 */
can2_device.type = RT_Device_Class_CAN;
can2_device.init = RT_NULL;
can2_device.open = RT_NULL;
can2_device.close = RT_NULL;
can2_device.read = rt_hw_can_read;
can2_device.write = rt_hw_can_write;
can2_device.control = rt_hw_can_control;
can2_device.private = RT_NULL;
rt_device_register(&can2_device, "can2", RT_DEVICE_FLAG_RDWR);
}
现在发送可以,接收一直进不了中断,请求帮助 中断产生与否和操作系统没关系呀 楼主想让他进到哪? 回复【2楼】aozima
楼主想让他进到哪?
-----------------------------------------------------------------------
CAN1_RX0_IRQHandler()这里
回复【1楼】ffxz
中断产生与否和操作系统没关系呀
-----------------------------------------------------------------------
是这样的,我是直接用RT_Thread 0.32 正式的Project107的项目来改的,现在就是这样的结果,我也觉得奇怪,之前不用操作系统可以进中断的 库升级,中断服务函数改名
CAN1_RX0_IRQHandler
==>
USB_LP_CAN1_RX0_IRQHandler
详见启动文件. 回复【4楼】aozima
库升级,中断服务函数改名
can1_rx0_irqhandler
==>
usb_lp_can1_rx0_irqhandler
详见启动文件.
-----------------------------------------------------------------------
改了没什么效果,还是进不去,真是奇怪 回复【楼主位】unknown
请问stm32f107 rt-thread 下can如何配置才能进接收中断?
目前配置如下:
static void nvic_configuration(void)
{
nvic_inittypedef nvic_initstructure;
//nvic_prioritygroupconfig(nvic_prioritygroup_2);
/* enable the can interrupt */
nvic_initstructure.nvic_irqchannel = can1_rx0_irqn;
nvic_initstructure.nvic_irqchannelpreemptionpriority = 0;
nvic_initstructure.nvic_irqchannelsubpriority = 0;
nvic_initstructu......
-----------------------------------------------------------------------
楼主在吗 我最近也在做CAN的项目 能不能把你的代码参考一下 QQ 120295276 http://www.ourdev.cn/bbs/bbs_content.jsp?bbs_sn=5358029&bbs_page_no=2&bbs_id=3020
看看这个帖子里的程序吧! 有没有可能是操作系统里的定义方式不一样呢???
页:
[1]