标题:
有关双CAN总线STM32F105系列例程源码
[打印本页]
作者:
FENYUN518
时间:
2018-8-21 10:43
标题:
有关双CAN总线STM32F105系列例程源码
这是我做的双CAN总线例程,试验通过。
单片机源程序如下:
/*
CAN1
USART1
CAN波特率、收发器 配置见CAN.h
stm32f10x.h中修改了外部晶振值8MHz
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_flash.h"
#include "stm32f10x_can.h"
#include "usart.h"
#include "CAN.h"
#include <stdio.h>
void RCC_Configuration(void);
void LED_Config(void);
void Delay(__IO uint32_t nCount);
CanTxMsg TxMsg1={0xAB,0,CAN_ID_STD,CAN_RTR_DATA,8,{0xAB,0,0,0,0,0,0,0}};
CanTxMsg TxMsg2={0xCD,0,CAN_ID_STD,CAN_RTR_DATA,8,{0xCD,0,0,0,0,0,0,0}};
int main(void)
{
/* System Clocks Configuration **********************************************/
RCC_Configuration();
LED_Config();
// 串口配置
USART_Configuration();
USART_STR(USART2,"++++++++++++++++++++++++\r\n");
USART_STR(USART2," CAN Study Board\r\n");
USART_STR(USART2,"++++++++++++++++++++++++\r\n");
// CAN1 配置
CAN1_Config(SET_CAN_SJW,SET_CAN_BS1,SET_CAN_BS2,SET_CAN_PRES);
Delay(2000);
// CAN2 配置
CAN2_Config(SET_CAN_SJW,SET_CAN_BS1,SET_CAN_BS2,SET_CAN_PRES);
while (1)
{
GPIO_ResetBits(GPIOC,GPIO_Pin_0);
GPIO_SetBits(GPIOC,GPIO_Pin_1);
GPIO_SetBits(GPIOC,GPIO_Pin_14);
GPIO_SetBits(GPIOC,GPIO_Pin_15);
Delay(5000);
Delay(5000);
GPIO_SetBits(GPIOC,GPIO_Pin_0);
GPIO_ResetBits(GPIOC,GPIO_Pin_1);
GPIO_SetBits(GPIOC,GPIO_Pin_14);
GPIO_SetBits(GPIOC,GPIO_Pin_15);
CAN_SendData(CAN1,&TxMsg1);
Delay(5000);
Delay(5000);
GPIO_SetBits(GPIOC,GPIO_Pin_0);
GPIO_SetBits(GPIOC,GPIO_Pin_1);
GPIO_ResetBits(GPIOC,GPIO_Pin_14);
GPIO_SetBits(GPIOC,GPIO_Pin_15);
Delay(5000);
Delay(5000);
GPIO_SetBits(GPIOC,GPIO_Pin_0);
GPIO_SetBits(GPIOC,GPIO_Pin_1);
GPIO_SetBits(GPIOC,GPIO_Pin_14);
GPIO_ResetBits(GPIOC,GPIO_Pin_15);
Delay(5000);
Delay(5000);
CAN_SendData(CAN2,&TxMsg2);
}
}
void RCC_Configuration(void)
{
/* Setup the microcontroller system. Initialize the Embedded Flash Interface,
initialize the PLL and update the SystemFrequency variable. */
SystemInit();
}
void Delay(__IO uint32_t nCount)
{
uint8_t x;
for(; nCount != 0; nCount--)
for(x=0;x<100;x++);
}
void LED_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
STM32_CAN500K USART_LED.rar
(458.73 KB, 下载次数: 188)
2018-8-22 02:13 上传
点击文件名下载附件
例程
下载积分: 黑币 -5
作者:
oliverlau2k11
时间:
2018-8-23 10:34
好东西,谢谢分享
作者:
askloser
时间:
2019-2-13 10:03
謝謝分享
作者:
fengbin
时间:
2019-5-5 16:53
可以发送下吗
905036191@qq.com
谢谢
作者:
h070230053
时间:
2019-7-29 15:49
謝謝分享
作者:
h070230053
时间:
2019-7-29 16:34
初学者,楼主可以分享吗
457268908@qq.com
谢谢
作者:
jflbr
时间:
2019-7-29 21:01
不错不错 .
作者:
辅导费分
时间:
2020-3-26 22:40
好东西,谢谢分享
作者:
jjwangxu2008
时间:
2020-4-10 09:04
好东西,谢谢分享
作者:
李天泽
时间:
2020-4-10 10:19
好东西
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1