标题:
stm32f105例程 CAN500K USART_LED
[打印本页]
作者:
774850156
时间:
2018-9-28 09:38
标题:
stm32f105例程 CAN500K USART_LED
stm32f105例程
单片机源程序如下:
/*
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
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
stm32f105.rar
(458.73 KB, 下载次数: 117)
2018-9-28 09:36 上传
点击文件名下载附件
下载积分: 黑币 -5
作者:
gws12345678
时间:
2018-10-31 12:15
楼主你好,我用你的代码,测试105r8 CAN时,发现发送的时候还是发不出去,在tx pin看不到波形,一直是高电平,打印transmit的返回值,发现mailbox值一直从1 2 3 4 4 4 后面就一直是4了,也就是从未发出去,楼主测试过吗?
作者:
xibo95
时间:
2019-1-29 14:30
正在学习,谢谢提供的资料。
作者:
h070230053
时间:
2019-7-30 09:49
正在学习,谢谢提供的资料
作者:
aaaaa111112222
时间:
2019-7-30 15:05
多谢分享,哈哈哈
作者:
99312312
时间:
2020-9-7 21:17
谢谢分享 学习一下 感恩付出
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1