第一范文网 - 专业文章范例文档资料分享平台

基于STM32的CAN总线的数据采集卡设计

来源:用户分享 时间:2025/6/7 21:55:21 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

附录1

35

附录2

程序原代码:

#include \

typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus; vu32 ret; /* for return of the interrupt handling */ volatile TestStatus TestRx; ErrorStatus HSEStartUpStatus;

TestStatus CAN_Polling(void); TestStatus CAN_Interrupt(void);

void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; // LED

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure CAN pin: RX */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Configure CAN pin: TX */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOB, &GPIO_InitStructure);

GPIO_PinRemapConfig(GPIO_Remap1_CAN1, ENABLE ); //IO脚到 PB8,PB9

}

36

重影射CAN

//系统中断管理

void NVIC_Configuration(void) { }

//配置系统时钟,使能各外设时钟 void RCC_Configuration(void) { }

//配置所有外设

SystemInit();

RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA

RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE); /* enabling interrupt */

NVIC_InitStructure.NVIC_IRQChannel=USB_LP_CAN1_RX0_IRQn;; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); #ifdef VECT_TAB_RAM

/* Set the Vector Table base location at 0x20000000 */ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */

/* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif

/* Configure the NVIC Preemption Priority Bits */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); NVIC_InitTypeDef NVIC_InitStructure;

|RCC_APB2Periph_GPIOB , ENABLE );

37

void Init_All_Periph(void) { }

int main(void) {

if (TestRx == FAILED) {

GPIO_SetBits(GPIOD, GPIO_Pin_11); } else {

GPIO_ResetBits(GPIOA, GPIO_Pin_1); } */

/* CAN transmit at 500Kb/s and receive by interrupt in loopback mode*/

TestRx = CAN_Interrupt();

/*

if (TestRx == FAILED) {

GPIO_ResetBits(GPIOA, GPIO_Pin_10); } else {

GPIO_ResetBits(GPIOA, GPIO_Pin_1); }

/* CAN transmit at 100Kb/s and receive by polling in loopback mode*/ TestRx = CAN_Polling(); Init_All_Periph(); RCC_Configuration(); GPIO_Configuration(); NVIC_Configuration();

38

搜索更多关于: 基于STM32的CAN总线的数据采集卡设计 的文档
基于STM32的CAN总线的数据采集卡设计.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c57min1uf6s62a898ee4z_10.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top