专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
STM32
求助,当伸手党,有没有CS5532 24位ADC芯片驱动程序
2020-01-10 19:45
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
STM32/STM8
12150
3
3
求助,当伸手党,有没有CS5532 ADC芯片驱动程序。有的话,留一份,非常感谢。
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
3条回答
OurWay
2020-01-10 23:36
很早以前写过一个,请无视英文注解,呵呵,供参考。
//The program for CS5532-ASZ
//This is a 24bit ADC and PGIA
//Made by OurWay and 2006/03/21
//#include <reg51.h>
//#include <intrins.h>
//根据实际情况定义
//sbit SDI5532 = P2^1;
//sbit SDO5532 = P2^2;
//sbit CLK5532 = P2^3;
//sbit CS5532 = P2^0;
//sbit ACC7 = ACC^7;
//sbit ACC0 = ACC^0;
//#define BYTE unsigned char
//#define WORD unsigned int
#define Adjust5532Run 0
#define ReadSADC5532Run 1
#define ReadMADC5532Run 1
//The ADC results varibles define
struct{
unsigned char top;
unsigned char high;
unsigned char mid;
unsigned char low;
}
RegDat;
//The CS5532-ASZ comm define
#define RegRead 0x08
#define RegWrite 0x00
//=== Offset Register ===
#define OffsetRS 0x09
//=== Gain Register ===
#define GainRS 0x0a
//=== Configuration Register ===
#define ConfigWrite 0x03 //write config
#define ConfigRead 0x0b //read config
#define PSS 0x80 //Power Save Select
#define PDW 0x40 //Power Down Mode
#define RS 0x20 //Reset System
#define RV 0x10 //Reset Valid
#define IS 0x08 //Input Short
#define GB 0x04 //Guard Signal Bit
#define VRS 0x02 //Voltage Reference Select(Ref>2.5V,VRS=0)
#define A1 0x01
#define A0 0x80
#define OLS 0x40
#define OGS 0x10
#define FRS 0x08
//=== Channel Setup Register ===
#define SetupCH1 0x05
#define SetupCH2 0x15
//Channel Select Bits
#define CH1 0x00 //CS1=0,CS0=0
#define CH2 0x40 //CS1=0,CS0=1
//Gain Bits
#define Gain1 0x00
#define Gain2 0x08
#define Gain4 0x10
#define Gain8 0x18
#define Gain16 0x20
#define Gain32 0x28
#define Gain64 0x30
//=== Converter mode ===
#define SingleC 0x80
#define ContinC 0xC0
#define Setup1 0x00
#define Setup2 0x08
#define Setup3 0x10
#define Setup4 0x18
#define Setup5 0x20
#define Setup6 0x28
#define Setup7 0x30
#define Setup8 0x38
//The data(8bit) form MCU to CS5532
void SendByte5532(unsigned char Dat)
{
unsigned char i;
CLK5532 = 0;
for(i=8;i>0;i--)
{
SDI5532=(bit)(Dat & 0x80);
CLK5532=1;
_nop_();_nop_();
_nop_();_nop_();
CLK5532=0;
_nop_();_nop_();
_nop_();_nop_();
Dat = Dat<<1;
}
SDI5532 = 1;
}
//The Setup CS5532's register
void WriteReg5532(BYTE command,BYTE low,BYTE mid,BYTE high,BYTE top)
{
CS5532 = 0;
SendByte5532(command);
SendByte5532(low);
SendByte5532(mid);
SendByte5532(high);
SendByte5532(top);
CS5532 = 1;
}
//The data(8bit) form CS5532 to MCU
unsigned char ReceiveByte5532(void)
{
unsigned char i;
ACC=0;
for(i=8;i>0;i--)
{
ACC=ACC<<1;
ACC0=SDO5532;
CLK5532=1;
_nop_();_nop_();
_nop_();_nop_();
CLK5532=0;
_nop_();_nop_();
_nop_();_nop_();
}
return(ACC);
}
//Receive ADC signal data form CS5532 to MCU
#if ReadSADC5532Run
void ReadSADC5532(unsigned char command)
{
CS5532 = 0;
SendByte5532(command);
do{_nop_();CLK5532=0;SDI5532=0;}while(SDO5532!=0);
SendByte5532(0x00); //8bit SCLK and SDI=0;
RegDat.top = ReceiveByte5532();
RegDat.high = ReceiveByte5532();
RegDat.mid = ReceiveByte5532();
RegDat.low = ReceiveByte5532();
CS5532 = 1;
}
#endif
#if ReadMADC5532Run
void ReadMADC5532(unsigned char command)
{
CS5532 = 0;
do{_nop_();}while(SDO5532!=0);
//SDO5532 = 1;
SendByte5532(command); //8bit SCLK and SDI=command;
RegDat.top = ReceiveByte5532();
RegDat.high = ReceiveByte5532();
RegDat.mid = ReceiveByte5532();
RegDat.low = ReceiveByte5532();
CS5532 = 1;
}
#endif
//Receive CS5532's Register from CS5532 to MCU
void ReadReg5532(unsigned char command)
{
CS5532 = 0;
SendByte5532(command);
RegDat.top = ReceiveByte5532();
RegDat.high = ReceiveByte5532();
RegDat.mid = ReceiveByte5532();
RegDat.low = ReceiveByte5532();
CS5532 = 1;
}
#if Adjust5532Run
void Adjust5532(unsigned char command)
{
CS5532 = 0;
SendByte5532(command);
do{_nop_();}while(SDO5532!=0);
SendByte5532(0x0a);
RegDat.top = ReceiveByte5532();
RegDat.high = ReceiveByte5532();
RegDat.mid = ReceiveByte5532();
RegDat.low = ReceiveByte5532();
CS5532 = 1;
}
#endif
//The initialization CS5532
void Init5532(void)
{
WriteReg5532(0xff,0xff,0xff,0xff,0xff);
WriteReg5532(0xff,0xff,0xff,0xff,0xff);
WriteReg5532(0xff,0xff,0xff,0xff,0xff);
WriteReg5532(0xff,0xff,0xff,0xff,0xfe);
}
//The CS5532-ASZ subpram end
//用的时间注意我定义的宏,这是个查询方式采集AD值的程序。
复制代码
加载中...
查看其它3个回答
一周热门
更多
>
相关问题
STM32F4上I2C(在PROTEUS中模拟)调试不通的问题
6 个回答
芯片供应紧张,准备换个MCU,MM32L系列替换STM32L系列的怎么样?
7 个回答
STM32同时使用两个串口进行数据收发时数据丢包的问题
5 个回答
STM32F103串口通信死机问题
4 个回答
STM32WLE5CC连接SX1268在LoRa模式下能与 SX1278互通吗?
2 个回答
相关文章
ST公司第一款无线低功耗单片机模块有效提高物联网设计生产效率
0个评论
如何实现对单片机寄存器的访问
0个评论
通过USB用STM32片内自带Bootloader下载程序及注意事项
0个评论
欲练此功必先自宫之STM32汇编启动,放慢是为了更好的前行
0个评论
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
STM32
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
- //The program for CS5532-ASZ
- //This is a 24bit ADC and PGIA
- //Made by OurWay and 2006/03/21
- //#include <reg51.h>
- //#include <intrins.h>
- //根据实际情况定义
- //sbit SDI5532 = P2^1;
- //sbit SDO5532 = P2^2;
- //sbit CLK5532 = P2^3;
- //sbit CS5532 = P2^0;
- //sbit ACC7 = ACC^7;
- //sbit ACC0 = ACC^0;
- //#define BYTE unsigned char
- //#define WORD unsigned int
- #define Adjust5532Run 0
- #define ReadSADC5532Run 1
- #define ReadMADC5532Run 1
- //The ADC results varibles define
- struct{
- unsigned char top;
- unsigned char high;
- unsigned char mid;
- unsigned char low;
- }
- RegDat;
- //The CS5532-ASZ comm define
- #define RegRead 0x08
- #define RegWrite 0x00
- //=== Offset Register ===
- #define OffsetRS 0x09
- //=== Gain Register ===
- #define GainRS 0x0a
- //=== Configuration Register ===
- #define ConfigWrite 0x03 //write config
- #define ConfigRead 0x0b //read config
- #define PSS 0x80 //Power Save Select
- #define PDW 0x40 //Power Down Mode
- #define RS 0x20 //Reset System
- #define RV 0x10 //Reset Valid
- #define IS 0x08 //Input Short
- #define GB 0x04 //Guard Signal Bit
- #define VRS 0x02 //Voltage Reference Select(Ref>2.5V,VRS=0)
- #define A1 0x01
- #define A0 0x80
- #define OLS 0x40
- #define OGS 0x10
- #define FRS 0x08
- //=== Channel Setup Register ===
- #define SetupCH1 0x05
- #define SetupCH2 0x15
- //Channel Select Bits
- #define CH1 0x00 //CS1=0,CS0=0
- #define CH2 0x40 //CS1=0,CS0=1
- //Gain Bits
- #define Gain1 0x00
- #define Gain2 0x08
- #define Gain4 0x10
- #define Gain8 0x18
- #define Gain16 0x20
- #define Gain32 0x28
- #define Gain64 0x30
- //=== Converter mode ===
- #define SingleC 0x80
- #define ContinC 0xC0
- #define Setup1 0x00
- #define Setup2 0x08
- #define Setup3 0x10
- #define Setup4 0x18
- #define Setup5 0x20
- #define Setup6 0x28
- #define Setup7 0x30
- #define Setup8 0x38
- //The data(8bit) form MCU to CS5532
- void SendByte5532(unsigned char Dat)
- {
- unsigned char i;
- CLK5532 = 0;
- for(i=8;i>0;i--)
- {
- SDI5532=(bit)(Dat & 0x80);
- CLK5532=1;
- _nop_();_nop_();
- _nop_();_nop_();
- CLK5532=0;
- _nop_();_nop_();
- _nop_();_nop_();
- Dat = Dat<<1;
- }
- SDI5532 = 1;
- }
- //The Setup CS5532's register
- void WriteReg5532(BYTE command,BYTE low,BYTE mid,BYTE high,BYTE top)
- {
- CS5532 = 0;
- SendByte5532(command);
- SendByte5532(low);
- SendByte5532(mid);
- SendByte5532(high);
- SendByte5532(top);
- CS5532 = 1;
- }
- //The data(8bit) form CS5532 to MCU
- unsigned char ReceiveByte5532(void)
- {
- unsigned char i;
- ACC=0;
- for(i=8;i>0;i--)
- {
- ACC=ACC<<1;
- ACC0=SDO5532;
- CLK5532=1;
- _nop_();_nop_();
- _nop_();_nop_();
- CLK5532=0;
- _nop_();_nop_();
- _nop_();_nop_();
- }
- return(ACC);
- }
- //Receive ADC signal data form CS5532 to MCU
- #if ReadSADC5532Run
- void ReadSADC5532(unsigned char command)
- {
- CS5532 = 0;
- SendByte5532(command);
- do{_nop_();CLK5532=0;SDI5532=0;}while(SDO5532!=0);
- SendByte5532(0x00); //8bit SCLK and SDI=0;
- RegDat.top = ReceiveByte5532();
- RegDat.high = ReceiveByte5532();
- RegDat.mid = ReceiveByte5532();
- RegDat.low = ReceiveByte5532();
- CS5532 = 1;
- }
- #endif
- #if ReadMADC5532Run
- void ReadMADC5532(unsigned char command)
- {
- CS5532 = 0;
- do{_nop_();}while(SDO5532!=0);
- //SDO5532 = 1;
- SendByte5532(command); //8bit SCLK and SDI=command;
- RegDat.top = ReceiveByte5532();
- RegDat.high = ReceiveByte5532();
- RegDat.mid = ReceiveByte5532();
- RegDat.low = ReceiveByte5532();
- CS5532 = 1;
- }
- #endif
- //Receive CS5532's Register from CS5532 to MCU
- void ReadReg5532(unsigned char command)
- {
- CS5532 = 0;
- SendByte5532(command);
- RegDat.top = ReceiveByte5532();
- RegDat.high = ReceiveByte5532();
- RegDat.mid = ReceiveByte5532();
- RegDat.low = ReceiveByte5532();
- CS5532 = 1;
- }
- #if Adjust5532Run
- void Adjust5532(unsigned char command)
- {
- CS5532 = 0;
- SendByte5532(command);
- do{_nop_();}while(SDO5532!=0);
- SendByte5532(0x0a);
- RegDat.top = ReceiveByte5532();
- RegDat.high = ReceiveByte5532();
- RegDat.mid = ReceiveByte5532();
- RegDat.low = ReceiveByte5532();
- CS5532 = 1;
- }
- #endif
- //The initialization CS5532
- void Init5532(void)
- {
- WriteReg5532(0xff,0xff,0xff,0xff,0xff);
- WriteReg5532(0xff,0xff,0xff,0xff,0xff);
- WriteReg5532(0xff,0xff,0xff,0xff,0xff);
- WriteReg5532(0xff,0xff,0xff,0xff,0xfe);
- }
- //The CS5532-ASZ subpram end
- //用的时间注意我定义的宏,这是个查询方式采集AD值的程序。
复制代码一周热门 更多>