標(biāo)題:
有關(guān)雙CAN總線STM32F105系列例程源碼
[打印本頁]
作者:
FENYUN518
時間:
2018-8-21 10:43
標(biāo)題:
有關(guān)雙CAN總線STM32F105系列例程源碼
這是我做的雙CAN總線例程,試驗通過。
單片機源程序如下:
/*
CAN1
USART1
CAN波特率、收發(fā)器 配置見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黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
STM32_CAN500K USART_LED.rar
(458.73 KB, 下載次數(shù): 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
可以發(fā)送下嗎
905036191@qq.com
謝謝
作者:
h070230053
時間:
2019-7-29 15:49
謝謝分享
作者:
h070230053
時間:
2019-7-29 16:34
初學(xué)者,樓主可以分享嗎
457268908@qq.com
謝謝
作者:
jflbr
時間:
2019-7-29 21:01
不錯不錯 .
作者:
輔導(dǎo)費分
時間:
2020-3-26 22:40
好東西,謝謝分享
作者:
jjwangxu2008
時間:
2020-4-10 09:04
好東西,謝謝分享
作者:
李天澤
時間:
2020-4-10 10:19
好東西
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1