云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 基于STM32的CAN总线的数据采集卡设计

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

  • 62 次阅读
  • 3 次下载
  • 2025/5/30 21:45:29

附录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总线的数据采集卡设计 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

附录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;

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com