资源简介
资料是用STM32F103单片机编写的CAN总线通信程序,程序在开发板上调试通过。利用固件库开发的。寄存器版本后续后上传提供学习。
代码片段和文件信息
#include “stm32f10x_lib.h“
#include “platform_config.h“
typedef enum {FAILED = 0 PASSED = !FAILED} TestStatus;
vu32 ret;
volatile TestStatus TestRx;
ErrorStatus HSEStartUpStatus;
/* Private functions ---------------------------------------------------------*/
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
TestStatus CAN_Polling(void);
TestStatus CAN_Interrupt(void);
int main(void)
{
#ifdef DEBUG
debug();
#endif
/* System Clocks Configuration */
RCC_Configuration();
/* NVIC Configuration */
NVIC_Configuration();
/* GPIO ports pins Configuration */
GPIO_Configuration();
/*Turn Off LEDs*/
GPIO_SetBits(GPIO_LED GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9);
/* CAN transmit at 100Kb/s and receive by polling in loopback mode */
TestRx = CAN_Polling();
if (TestRx == FAILED)
{
/* Turn on led connected to GPIO_LED pin8 (LD3) */
GPIO_ResetBits(GPIO_LED GPIO_Pin_8);
}
else
{
/* Turn on led connected to GPIO_LED pin6 (LD1) */
GPIO_ResetBits(GPIO_LED GPIO_Pin_6);
}
/* CAN transmit at 500Kb/s and receive by interrupt in loopback mode */
TestRx = CAN_Interrupt();
if (TestRx == FAILED)
{
/* Turn on led connected to GPIO_LED pin9 (LD4) */
GPIO_ResetBits(GPIO_LED GPIO_Pin_9);
}
else
{
/* Turn on led connected to GPIO_LED pin7 (LD2) */
GPIO_ResetBits(GPIO_LED GPIO_Pin_7);
}
while (1)
{
}
}
void RCC_Configuration(void)
{
/* RCC system reset(for debug purpose) */
RCC_DeInit();
/* Enable HSE */
RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready */
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* HCLK = SYSCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK */
RCC_PCLK1Config(RCC_HCLK_Div1);
/* Select HSE as system clock source */
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);
/* Wait till HSE is used as system clock source */
while(RCC_GetSYSCLKSource() != 0x04)
{
}
}
/* GPIOA and GPIO_LED clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIO_LED ENABLE);
/* CAN Periph clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure GPIO_LED pin6 pin7 pin8 and pin9 as Output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIO_LED &GPIO_InitStructure);
/* Configure CAN pin: RX */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.G
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4608 2009-07-10 22:21 STM32_CAN\CAN.opt.bak
文件 194 2009-07-08 04:45 STM32_CAN\CAN.plg
文件 4504 2009-07-08 04:47 STM32_CAN\CAN.Uv2.bak
....... 71563 2018-08-29 15:36 STM32_CAN\CAN.uvgui.Administrator
....... 22245 2018-08-29 15:36 STM32_CAN\CAN.uvopt
....... 21447 2018-08-29 15:18 STM32_CAN\CAN.uvproj
文件 20689 2010-11-13 05:38 STM32_CAN\CAN_CAN.dep
文件 4607 2009-07-08 04:47 STM32_CAN\CAN_Opt.Bak
文件 70 2009-07-08 04:45 STM32_CAN\CAN_Target 1.dep
文件 0 2009-07-08 04:44 STM32_CAN\CAN_Uv2.Bak
....... 164480 2010-11-13 05:40 STM32_CAN\CAN_uvopt.bak
....... 20746 2010-11-02 08:33 STM32_CAN\CAN_uvproj.bak
文件 2225 2008-09-22 21:19 STM32_CAN\Source\FWLib\inc\cortexm3_macro.h
文件 18854 2008-09-22 21:19 STM32_CAN\Source\FWLib\inc\stm32f10x_adc.h
文件 6911 2008-09-22 21:19 STM32_CAN\Source\FWLib\inc\stm32f10x_bkp.h
文件 12279 2008-09-22 21:19 STM32_CAN\Source\FWLib\inc\stm32f10x_can.h
文件 1881 2008-09-22 21:19 STM32_CAN\Source\FWLib\inc\stm32f10x_crc.h
文件 9598 2008-09-22 21:19 STM32_CAN\Source\FWLib\inc\stm32f10x_dac.h
文件 2859 2008-09-22 21:19 STM32_CAN\Source\FWLib\inc\stm32f10x_dbgmcu.h
文件 17974 2008-09-22 21:19 STM32_CAN\Source\FWLib\inc\stm32f10x_dma.h
文件 5776 2008-09-22 21:19 STM32_CAN\Source\FWLib\inc\stm32f10x_exti.h
文件 13996 2008-09-22 21:19 STM32_CAN\Source\FWLib\inc\stm32f10x_flash.h
文件 19041 2008-09-22 21:19 STM32_CAN\Source\FWLib\inc\stm32f10x_fsmc.h
文件 14820 2008-09-22 21:19 STM32_CAN\Source\FWLib\inc\stm32f10x_gpio.h
文件 16213 2008-09-22 21:19 STM32_CAN\Source\FWLib\inc\stm32f10x_i2c.h
文件 3414 2008-09-22 21:19 STM32_CAN\Source\FWLib\inc\stm32f10x_iwdg.h
文件 3200 2008-09-22 21:19 STM32_CAN\Source\FWLib\inc\stm32f10x_lib.h
文件 28290 2008-09-22 21:19 STM32_CAN\Source\FWLib\inc\stm32f10x_map.h
文件 19198 2008-09-22 21:19 STM32_CAN\Source\FWLib\inc\stm32f10x_nvic.h
文件 3865 2008-09-22 21:19 STM32_CAN\Source\FWLib\inc\stm32f10x_pwr.h
............此处省略49个文件信息
相关资源
- 用51单片机实现小车循迹和LCD显示
- 基于51单片机和OV7670摄像头的颜色跟踪
- 一种高精度旋转编码器单片机计数电
- 单片机晶闸管触发电路及程序设计方
- 16*16点阵LED串口在线控制程序
- 用于单片机的模糊控制算法程序
- 基于51单片机的4路智能抢答器
- 在51单片机上实现的完整功能的计算器
- 基于C8051F系列单片机的无刷直流电机
- 飞思卡尔DG128单片机ds18b20程序
- 天狼星单片机原理图
- 单片机常用电源电路
- 单片机课程设计任务书,单片机课程
- 单片机电子密码锁课程设计
- 利用51单片机产生可调PWM波
- 基于单片机的八音盒详细设计步骤
- ScanWebDirectory 网站目录扫描工具
- 基于周立功的usbcan接口卡的labview开发
- STC89系列单片机选型一览表
- 采用STC12C5A60S2单片机作为主控芯片实
- protelDXP单片机89C51等的元件库
- RC522单片机读写卡程序
- 51单片机延时算法
- 基于51单片机的智能窗帘系统全套资料
- Advanced IP Scanner
- 单片机与单片机之间串口通信,注释
- 51单片机频率精确测量C程序
- ads1115驱动,msp430f149单片机
- 肺活量监测,程序部分,STC89C51单片机
- 肺活量监测,STC89C51单片机和AD0832AD转
评论
共有 条评论