LDC1000在STM32的程序 LDC1000的STM32驱动源程序

发布者:Radiant777最新更新时间:2024-07-26 来源: elecfans关键字:LDC1000  STM32  驱动源程序 手机看文章 扫描二维码
随时随地手机看文章

本文主要介绍了关于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);

[1] [2]
关键字:LDC1000  STM32  驱动源程序 引用地址:LDC1000在STM32的程序 LDC1000的STM32驱动源程序

上一篇:关于STM32CubeMX重大升级
下一篇:stm32 系列ili9341lcd屏驱动程序

小广播
最新单片机文章
何立民专栏 单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

厂商技术中心

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

 
机器人开发圈

电子工程世界版权所有 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2026 EEWORLD.com.cn, Inc. All rights reserved