本文主要介绍了关于LDC1000的STM32驱动源程序,希望能对各位有所帮助。
LDC1000在STM32的程序
#include 'stm32f10x.h'
#include 'usart1.h'
#include 'led.h'
#include 'delay.h'
#include 'stdio.h'
#include 'ldc1000.h'
#include 'pwm.h'
/*----------------------------------------
全局变量
----------------------------------------*/
extern uint8_t RegArray[REG_LEN];
int8_t i = 0;
/*----------------------------------------
主函数
----------------------------------------*/
int main(void)
{
DelayInit();
LED_GPIO_Config();
USART1_Config();
PWM_TIM4_CH1_Config(8,0); //输出8MHz时钟给TBCLK,LDC1000需要8MHz时钟方可运行
delayms(100);
LDC1000_Init();
//printf('LDC1000-DEMOrn');
while(1)
{ //LDC1000_WriteReg(LDC1000_CMD_SENSORFREQ, 0x94);
//delayms(10);
printf('0x00 = %xrn',LDC1000_ReadReg(0x00));
printf('0x01 = %xrn',LDC1000_ReadReg(0x01));
printf('0x02 = %xrn',LDC1000_ReadReg(0x02));
printf('0x03 = %xrn',LDC1000_ReadReg(0x03));
printf('0x04 = %xrn',LDC1000_ReadReg(0x04));
printf('0x05 = %xrn',LDC1000_ReadReg(0x05));
printf('0x06 = %xrn',LDC1000_ReadReg(0x06));
printf('0x07 = %xrn',LDC1000_ReadReg(0x07));
printf('0x08 = %xrn',LDC1000_ReadReg(0x08));
printf('0x09 = %xrn',LDC1000_ReadReg(0x09));
printf('0x0A = %xrn',LDC1000_ReadReg(0x0A));
printf('0x0B = %xrn',LDC1000_ReadReg(0x0B));
printf('0x20 = %xrn',LDC1000_ReadReg(0x20));
printf('0x21 = %xrn',LDC1000_ReadReg(0x21));
printf('0x22 = %xrn',LDC1000_ReadReg(0x22));
printf('0x23 = %xrn',LDC1000_ReadReg(0x23));
printf('0x24 = %xrn',LDC1000_ReadReg(0x24));
printf('0x25 = %xrn',LDC1000_ReadReg(0x25));
// LDC1000_ReadBytes(LDC1000_CMD_REVID,&RegArray[0],12);
// for(i=0; i<12; i++)
// {
// printf('Addr=%x Data=%xrn',i,RegArray);
// }
delayms(1000);
}
}
单片机源程序如下:
#include 'ldc1000.h'
/*----------------------------------------
全局变量
----------------------------------------*/
uint8_t RegArray[REG_LEN];
/*----------------------------------------
宏定义
----------------------------------------*/
#define CSB_0 GPIOB->BRR = GPIO_Pin_7
#define CSB_1 GPIOB->BSRR = GPIO_Pin_7
/*----------------------------------------
函数功能: LDC1000初始化
函数参数: 无
----------------------------------------*/
void LDC1000_Init(void)
{
LDC1000_GPIO_Init();
LDC1000_SPI_Init();
LDC1000_WriteReg(LDC1000_CMD_RPMAX, 0x13);
LDC1000_WriteReg(LDC1000_CMD_RPMIN, 0x3A);
LDC1000_WriteReg(LDC1000_CMD_SENSORFREQ, 0x94);
LDC1000_WriteReg(LDC1000_CMD_LDCCONFIG, 0x17);
LDC1000_WriteReg(LDC1000_CMD_CLKCONFIG, 0x02);
LDC1000_WriteReg(LDC1000_CMD_INTCONFIG, 0x02);
LDC1000_WriteReg(LDC1000_CMD_THRESHILSB, 0x50);
LDC1000_WriteReg(LDC1000_CMD_THRESHIMSB, 0x14);
LDC1000_WriteReg(LDC1000_CMD_THRESLOLSB, 0xC0);
LDC1000_WriteReg(LDC1000_CMD_THRESLOMSB, 0x12);
LDC1000_WriteReg(LDC1000_CMD_PWRCONFIG, 0x01);
}
/*----------------------------------------
函数功能: LDC1000 GPIO初始化
函数参数: IO口连接图
+5V <-> +5V
DCLK <-> PB6 <-> TIM4_CH1
SCLK <-> PA5 <-> SPI1_SCK
SDI <-> PA7 <-> SPI1_MOSI
SDO <-> PA6 <-> SPI1_MISO
VIO <-> 3V3
GND <-> GND
INT <-> PC2 <-> GPIO
CSB <-> PB7 <-> GPIO
GND <-> GND
----------------------------------------*/
void LDC1000_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //记住使能AFIO时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB| RCC_APB2Periph_GPIOC , ENABLE);
//PB6->PWM_OUTPUT
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //PB6复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//A5->SCK A6->MISO A7->MOSI
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //SPI用复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
//PC2->INT
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);
//PB7->CSB
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);
上一篇:关于STM32CubeMX重大升级
下一篇:stm32 系列ili9341lcd屏驱动程序
推荐阅读最新更新时间:2024-11-03 07:07
设计资源 培训 开发板 精华推荐
- 使用 LTC3637HDHC 5V-76V 输入至 5V 输出、具有软启动功能的 1A 稳压器的典型应用
- LT3692AEFE、12V、3.3V、2.5V、1.2V 四路输出、具有外部同步、输出排序和跟踪应用的典型应用电路
- ADR3425 2.5V 输出微功率、高精度电压基准的典型应用
- LT3470AHDDB 1.8V 降压转换器的典型应用电路
- L6234 三相电机驱动器应用说明
- EVAL-AD73322EB,低成本、低功耗、CMOS 通用双模拟前端评估板
- 用于高输出电流短路保护的 L78L33AB 正电压稳压器的典型应用
- LTC2992HDE-1 四象限功率监视器的典型应用(10kHz I2C 接口)
- LF25CDT-TR 2.5V 极低压降稳压器的典型应用
- 采用 VIPer22A PWM 控制器的恒流 (1.05A) LED 驱动器