|
最近使用STM32F103编写的LDC1314多通道测试程序,里面包含LDC1314的数据手册,请认真读取分析,特别是寄存器操作那一块的内容。
单片机源程序如下:
- #include "ldc1314.h"
- #include "myiic.h"
- #include "delay.h"
- u16 LDC1314_Read2Byte(u8 reg_addr)
- {
- u16 reg_data=0;
- u16 temp=0;
- IIC_Start();
- IIC_Send_Byte(WRITE_ADDR);
- if(IIC_Wait_Ack())return 0;
- IIC_Send_Byte(reg_addr);
- if(IIC_Wait_Ack())return 0;
- IIC_Start();
- IIC_Send_Byte(READ_ADDR);
- if(IIC_Wait_Ack())return 0;
- reg_data= IIC_Read_Byte(1);
- reg_data=(reg_data<<8)&0xFF00;
- temp=IIC_Read_Byte(0);
- IIC_Stop();
-
- reg_data|=temp;
- return reg_data;
- }
- u8 LDC1314_Write2Byte(u8 reg_addr,u16 reg_data)
- {
- u8 data_high=(u8)((reg_data&0xFF00)>>8);
- u8 data_low=(u8)reg_data&0x00FF;
- IIC_Start();
- IIC_Send_Byte(WRITE_ADDR);
- if(IIC_Wait_Ack())return 0;
- IIC_Send_Byte(reg_addr );
- if(IIC_Wait_Ack())return 0;
- IIC_Send_Byte(data_high);
- if(IIC_Wait_Ack())return 0;
- IIC_Send_Byte(data_low);
- if(IIC_Wait_Ack())return 0;
- IIC_Stop();
- delay_ms(5);
- return 1;
- }
- void LDC1314_Init_Multi()
- {
- LDC1314_Write2Byte(RCOUNT0,0XFFFF);
- LDC1314_Write2Byte(RCOUNT1,0XFFFF);
- LDC1314_Write2Byte(RCOUNT2,0XFFFF);
- LDC1314_Write2Byte(RCOUNT3,0XFFFF);
-
- LDC1314_Write2Byte(SETTLECOUNT0,0x000A);
- LDC1314_Write2Byte(SETTLECOUNT1,0x000A);
- LDC1314_Write2Byte(SETTLECOUNT2,0x000A);
- LDC1314_Write2Byte(SETTLECOUNT3,0x000A);
-
- LDC1314_Write2Byte(CLK_DIVIDERS0,0x2002);
- LDC1314_Write2Byte(CLK_DIVIDERS1,0x2002);
- LDC1314_Write2Byte(CLK_DIVIDERS2,0x2002);
- LDC1314_Write2Byte(CLK_DIVIDERS3,0x2002);
-
- LDC1314_Write2Byte(ERROR_CONFIG,0X0000);
- LDC1314_Write2Byte(RESET_DEV,0x0000);
-
- // LDC1314_Write2Byte(MUX_CONFIG,0X420C);
- LDC1314_Write2Byte(MUX_CONFIG,0xC20D);
-
- LDC1314_Write2Byte(DRIVE_CURRENT0,0xF800);
- LDC1314_Write2Byte(DRIVE_CURRENT1,0xF800);
- LDC1314_Write2Byte(DRIVE_CURRENT2,0xF800);
- LDC1314_Write2Byte(DRIVE_CURRENT3,0xF800);
-
- LDC1314_Write2Byte(CONFIG,0x1401);
- }
- void LDC1314_Init_single()
- {
- LDC1314_Write2Byte(RCOUNT0,0xFFFF);
- LDC1314_Write2Byte(SETTLECOUNT0,0x0000);
- LDC1314_Write2Byte(CLK_DIVIDERS0,0x2002);
- LDC1314_Write2Byte(RESET_DEV,0x0000);
- LDC1314_Write2Byte(DRIVE_CURRENT0,0xF800);
- LDC1314_Write2Byte(CONFIG,0x1441); //大于1.5mA电流(仅通道0使用)
- }
- u16 LDC_read_CHx(u8 CHx) //读Channel x Conversion Result
- {
- u8 reg_addr1 = 0;
- u16 val = 0;
- switch(CHx)
- {
- case 0:
- {
- reg_addr1 = DATA0_MSB;
- }break;
- case 1:
- {
- reg_addr1 = DATA1_MSB;
- }break;
- case 2:
- {
- reg_addr1 = DATA2_MSB;
- }break;
- case 3:
- {
- reg_addr1 = DATA3_MSB;
- }break;
- default: return 0; //输入错误
- }
-
- val = LDC1314_Read2Byte(reg_addr1); //读取寄存器值
- return val;
- }
-
复制代码
所有资料51hei提供下载:
LDC1314 模块.7z
(1.69 MB, 下载次数: 57)
|
|