|
发表于 2012-8-7 13:47:42
|
显示全部楼层
I2C的驱动自己写吧,下面是我写的程序,好好看看datasheet的寄存器,不难的
#include <msp430x26x.h>
#include "I2C.h"
#include "ADS1115.h"
#define uchar unsigned char
#define uint unsigned int
//=========================================
//函数功能:配置ADS1115
//channel:0~3
//mode:0~4
// 0:Vref = 4.096V
// 1: Vref = 2.048V
// 2: Vref = 1.024V
// 3: Vref = 0.512V
// 4: Vref = 0.256V
//=========================================
void Configure(uchar channel,uchar mode)
{
uchar ConfigWord[4];
uchar i,CongigWordH;
CongigWordH = 0xc2 + (channel << 4) + (mode << 1); //设置配置字高字节
ConfigWord[0] = 0x90; //地址 + 写命令
ConfigWord[1] = 0x01; //指向配置寄存器
ConfigWord[2] = CongigWordH;//配置字高字节
ConfigWord[3] = 0xe3; //配置字低字节
I2C_Start();
for(i = 0;i < 4;i++)
{
I2C_SendByte(ConfigWord[i]);
}
I2C_Stop();
}
void PointRegister()
{
I2C_Start();
I2C_SendByte(0x90); //地址 + 写命令
I2C_SendByte(0x00); //指向转换结果寄存器
I2C_Stop();
}
uint Read_ADS1115(uchar channel,uchar mode)
{
uchar resultL,resultH;
uint result;
Configure(channel,mode);
PointRegister();
delayms(10);
I2C_Start();
I2C_SendByte(0x91); //地址 + 读命令
resultH = I2C_ReadByte();
resultL = I2C_ReadByte();
I2C_Stop();
result = (resultH << 8) | resultL;
return result;
}
void Init_ADS1115()
{
P2DIR |= BIT0 + BIT1;
} |
|