资源简介
该代码使用使stm32平台成功移植CANopen协议,作从站使用
代码片段和文件信息
#include
#include
#include “canfestival.h“
#include “timer_canfestival.h“
#include “stm32f10x_tim.h“
#include “led.h“
/************************** Modul variables **********************************/
// Store the last timer value to calculate the elapsed time
static TIMEVAL last_time_set = TIMEVAL_MAX;
__IO uint16_t CCR1_Val = 49152;
void setTimer(TIMEVAL value)
{
uint16_t capture = 0;
capture = TIM_GetCapture1(TIM4);
TIM_SetCompare1(TIM4 capture + value);
}
TIMEVAL getElapsedTime(void)
{
uint16_t timer = TIM_GetCounter(TIM4);
/* Calculate the time difference */
/* return timer > last_time_set ? timer - last_time_set : last_time_set - timer; */
/* I think this should be fixed to
16 bit substraction */
timer = timer - last_time_set;
return timer;
}
/* TIM5 configure */
static void TIM4_Configuration(void)
{
/* 时钟及分频设置 */
{
TIM_TimebaseInitTypeDef TIM_TimebaseStructure;
/* Time base configuration */
/* 16M / 16 = 1us */
TIM_TimebaseStructure.TIM_Prescaler = 16- 1;
//计数模式:向上计数
TIM_TimebaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimebaseStructure.TIM_Period = 0xFFFF;
TIM_TimebaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
//重新计数的起始值
TIM_TimebaseStructure.TIM_RepetitionCounter = 0;
TIM_TimebaseInit(TIM4 &TIM_TimebaseStructure);
}
{
TIM_OCInitTypeDef TIM_OCInitStructure;
/* Output Compare Timing Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR1_Val;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM4 &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM4 TIM_OCPreload_Disable);
}
/* TIM IT enable */
TIM_ITConfig(TIM4 TIM_IT_CC1 ENABLE);
/* TIM enable counter */
TIM_Cmd(TIM4 ENABLE);
}
static void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the TIM5 global Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
static void RCC_Configuration(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIOENABLE);
/* TIM4 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4 ENABLE);
/* clock enable */
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA ENABLE);
}
void TIM4_start(void)
{
RCC_Configuration();
/* configure TIM4 for remote and encoder */
NVIC_Configuration();
TIM4_Configuration();
}
void TIM4_IRQHandler(void)
{
if (TIM_GetITStatus(TIM4 TIM_IT_CC1) != RESET)
{
TIM_ClearITPendingBit(TIM4 TIM_IT_CC1);
last_time_set = TIM_GetCounter(TIM4);
TimeDispatch();
// ((GPIOB->ODR & GPIO_Pin_0
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 53 2014-09-09 11:19 slave_canfestival\Readme.txt
文件 3092 2014-09-09 10:54 slave_canfestival\CanFestival\drivers\STM32\STM32_timer_canfestival.c
文件 7872 2012-04-26 12:11 slave_canfestival\CanFestival\example\Master.c
文件 497 2012-02-04 16:08 slave_canfestival\CanFestival\example\Master.h
文件 14420 2013-09-10 10:12 slave_canfestival\CanFestival\example\Master_board.c
文件 3048 2009-04-06 10:30 slave_canfestival\CanFestival\example\platform_config.h
文件 3170 2013-10-12 14:36 slave_canfestival\CanFestival\example\Slave.c
文件 502 2012-02-04 16:08 slave_canfestival\CanFestival\example\Slave.h
文件 12978 2014-01-10 09:34 slave_canfestival\CanFestival\example\Slave_board.c
文件 28030 2012-04-13 10:43 slave_canfestival\CanFestival\example\TestMaster.c
文件 1340 2012-02-04 16:08 slave_canfestival\CanFestival\example\TestMaster.h
文件 921 2012-04-06 11:46 slave_canfestival\CanFestival\example\TestMasterSlave.h
文件 72796 2014-01-10 10:34 slave_canfestival\CanFestival\example\TestSlave.c
文件 8547 2013-09-07 09:58 slave_canfestival\CanFestival\example\TestSlave.h
文件 1471 2013-08-28 16:51 slave_canfestival\CanFestival\include\can.h
文件 3714 2013-09-10 10:40 slave_canfestival\CanFestival\include\can_driver.h
文件 10099 2013-09-09 17:41 slave_canfestival\CanFestival\include\data.h
文件 1698 2011-12-15 13:51 slave_canfestival\CanFestival\include\dcf.h
文件 6014 2014-01-08 11:22 slave_canfestival\CanFestival\include\def.h
文件 3017 2011-12-15 13:51 slave_canfestival\CanFestival\include\emcy.h
文件 3151 2011-12-15 13:51 slave_canfestival\CanFestival\include\lifegrd.h
文件 9306 2013-09-10 10:46 slave_canfestival\CanFestival\include\lss.h
文件 3115 2011-12-15 13:51 slave_canfestival\CanFestival\include\nmtMaster.h
文件 1728 2011-12-15 13:51 slave_canfestival\CanFestival\include\nmtSlave.h
文件 12842 2011-12-15 13:51 slave_canfestival\CanFestival\include\objacces.h
文件 4075 2011-12-15 13:51 slave_canfestival\CanFestival\include\objdictdef.h
文件 5047 2011-12-15 13:51 slave_canfestival\CanFestival\include\pdo.h
文件 19240 2012-04-25 15:31 slave_canfestival\CanFestival\include\sdo.h
文件 3845 2011-12-15 13:51 slave_canfestival\CanFestival\include\states.h
文件 2184 2011-12-15 13:51 slave_canfestival\CanFestival\include\sync.h
............此处省略246个文件信息
相关资源
- 基于STM32F4x9的LCD显示
- VS1053B编解码器的VDR分布式声音采集卡
- stm32的DAC播放音乐文件
- STM32+TMC5160代码电路图.rar
- 基于STM32的深海钻机甲板控制系统
- stm32f103.SchDoc
- STM32F103 USART+DMA
- DMA+stm32 407.zip
- 4_USART串口通信(空闲中断+DMA.zip
- stm32f105-usart-DMA收发demo
- STM32F042F6P6 Uart12DMA;发送中断接收
- 基于STM32的嵌入式双目图像采集系统设
- 基于STM32F103C8单片机的晶联讯电子JL
- 基于STM32的温湿度检测系统实现
- stm32F4+w5300
- 14284969_《STM32单片机应用与全案例实践
-
ST-li
nk-V2的SWD仿真使用方法.docx - 安富莱STM32开发板资料
- STM32F103实现OV7670摄像头显示
- STM32F207学习板例程
- STM32F103VCT6TR - High-density performance lin
- STM32 SRAM启动的 KeiL 配置
- STM32的IAP-Bootloader程序
- STM32例程之Bootloader
- stm32f103 虚拟U盘,调试成功的
- 基于stm32F103vct6的SD卡FATFS文件系统移植
- STM32F030从机中断接收的iic代码,附带
- FreeModbus_Slave+STM32F407+USART2代码亲测可
- STM32+1602液晶proteus仿真.zip
- STM32循迹小车
评论
共有 条评论