LDC1000 in the STM32 program LDC1000 STM32...

This article mainly introduces the STM32 driver source program of LDC1000, I hope it can be helpful to you. LDC1000 in STM32 program
#include "stm32f10x.h" #include "usart1.h" #include "led.h" #include "delay.h" #include "stdio.h" #include "ldc1000.h" #include "pwm.h" / *---------------------------------------- Global Variables------- ---------------------------------*/ extern uint8_t RegArray[REG_LEN]; int8_t i = 0; /*- --------------------------------------- Main function --------- -------------------------------*/ int main(void) {DelayInit(); LED_GPIO_Config(); USART1_Config() ; PWM_TIM4_CH1_Config(8,0); //Output 8MHz clock to TBCLK, LDC1000 needs 8MHz clock to run delayms(100); LDC1000_Init(); //printf("LDC1000-DEMO"); while(1) {// LDC1000_WriteReg(LDC1000_CMD_SENSORFREQ, 0x94); //delayms(10); printf("0x00 = %x",LDC1000_ReadReg(0x00)); printf("0x01 = %x",LDC1000_ReadReg(0x01)); printf("0x02 =% x",LDC1000_ReadReg(0x02)); printf("0x03 = %x",LDC1000_ReadReg(0x03)); printf("0x04 = %x",LDC1000_ReadR eg(0x04)); printf("0x05 = %x",LDC1000_ReadReg(0x05)); printf("0x06 = %x",LDC1000_ReadReg(0x06)); printf("0x07 = %x",LDC1000_ReadReg(0x07)) ; printf("0x08 = %x",LDC1000_ReadReg(0x08)); printf("0x09 = %x",LDC1000_ReadReg(0x09)); printf("0x0A = %x",LDC1000_ReadReg(0x0A)); printf("0x0B = %x",LDC1000_ReadReg(0x0B)); printf("0x20 = %x",LDC1000_ReadReg(0x20)); printf("0x21 = %x",LDC1000_ReadReg(0x21)); printf("0x22 = %x", LDC1000_ReadReg(0x22)); printf("0x23 = %x",LDC1000_ReadReg(0x23)); printf("0x24 = %x",LDC1000_ReadReg(0x24)); printf("0x25 = %x",LDC1000_ReadReg(0x25)) ; // LDC1000_ReadBytes(LDC1000_CMD_REVID,&RegArray[0],12); // for(i=0; i // {// printf("Addr=%x Data=%x",i,RegArray); //} delayms(1000);}}
The source program of the single chip microcomputer is as follows:
#include "ldc1000.h" /*---------------------------------------- Global Variable----------------------------------------*/ uint8_t RegArray[REG_LEN]; / *---------------------------------------- Macro definition------- ---------------------------------*/ #define CSB_0 GPIOB->BRR = GPIO_Pin_7 #define CSB_1 GPIOB-> BSRR = GPIO_Pin_7 /*---------------------------------------- Function function: LDC1000 initialization Function parameters: None----------------------------------------*/ 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(L DC1000_CMD_THRESLOLSB, 0xC0); LDC1000_WriteReg(LDC1000_CMD_THRESLOMSB, 0x12); LDC1000_WriteReg(LDC1000_CMD_PWRCONFIG, 0x01);} /*---------------------------- ------------ Function: LDC1000 GPIO initialization function parameters: IO port connection diagram +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); // remember AFIO clock enable 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 multiplexed push-pull output GPIO_Init Structure.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_Init = push GPIO. 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_Speed_50MHz; GPIO_Speed_InitStructure; GPIO_InitStructure. >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);} /*-------------------- -------------------- Function function: SPI parameter initialization function parameter: The clock frequency of LDC1000 must be 4.2MHz and cannot exceed 5MHz, cannot be lower than 4MHz, otherwise the module will not It can communicate normally, so the SPI baud rate frequency division coefficient selects 16 frequency division. --------- -------------------------------*/ void LDC1000_SPI_Init(void) {SPI_InitTypeDef SPI_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE); / /Enable APB2 peripheral clock SPI_InitStructure.SPI_Direction = SPI_DirecTIon_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //SPI master SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //Data format 8-bit SPI_Init_POL, high polarity SPI_Init_POL = high SPI_InitStructure; //. Yes SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; //The first and second edges of the clock phase can be triggered SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRateRatePrescaler = SPI_BaudRateMSB before SPI_InitStructure_16; //Must be 16 before SPI_InitStructure SPI_InitStructure.SPI_CRCPolynomial = 7; //CRC polynomial check, optional SPI_Init(SPI1,&SPI_InitStructure); SPI_Cmd(SPI1,ENABLE);} /*--------------- ------------------------- Function: LDC1000 write Register function parameters:-addr register address-dat data--------------------------------------- -*/ void LDC1000_WriteReg(int8_t addr, uint8_t dat) {addr = addr & 0x7F; //MSB is 0 write register, 1 is read register CSB_0; // LDC1000_SendByte(addr); // LDC1000_SendByte(dat); SPI_I2S_SendData(SPI1 , addr); while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); SPI_I2S_SendData(SPI1, dat); while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) ==; RESET);* -------------------------------- Function function: LDC1000 read register function parameter:-addr register address ----- -----------------------------------*/ uint8_t LDC1000_ReadReg(int8_t addr) {uint8_t temp; addr = addr | 0x80; //MSB is 1 to read register, 0 to write register CSB_0; SPI_I2S_SendData(SPI1, addr); while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); SPI_I2S_SendData(SPI1, 0xStatus); while( SPI_I2S_FLAG_TXE) == RESET); temp = (uint8_t)SPI_I2S_ReceiveDa ta(SPI1); // LDC1000_SendByte(addr); // temp = LDC1000_SendByte(0x00); CSB_1; return temp;} /*--------------------- ------------------- Function function: Send one byte of data to LDC1000 Function parameter: Data to be sent dat Return value: Data sent back by the device ----- -----------------------------------*/ uint8_t LDC1000_SendByte(uint8_t dat) {while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); SPI_I2S_SendData(SPI1, dat); while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET); return (uint8_t)SPI1->DR;} /*----------- ----------------------------- Function function: Read one byte of LDC1000 Function parameter: Null Return value: Sent from the device One byte of data----------------------------------------*/ uint8_t LDC1000_ReadByte(void ) {return 0x00;} /*---------------------------------------- Function function : Read LDC1000 len bytes………………………………Limited to the length of this article, please download the attachment from electronic enthusiasts for the rest of the code.…………,
》》》》》》》》》》》》》LDC1000-STM32 Driver

Frame For Iphone X13 Pro

Frame For Iphone X13 Pro,13 Promax Frame With Glue,Metal Frame For Iphone 13Promax,Lcd Frame For Iphone 13Promax

Shenzhen Xiangying touch photoelectric co., ltd. , https://www.starstp.com

Posted on