Other Parts Discussed in Thread: ADS1298
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:ADS1298 是否有用于以 c 语言读取 ADS1298的示例代码。
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
您好!
这是我在互联网上从 Arduino 中参考的代码。
我能够读取 ID 寄存器上的0x92。
您能否检查 代码的序列/命令是否正常?
#include
#define MOSI1 51 //MOSI
#define MISO1 50 // MISO
#define CLK1 52 //SCK
#define PIN_CS 2
#define PIN_RESET 3
#define PIN_START 4
#define PIN_DRDY 5
#define READ 0x20
#define WRITE 0x40
#define ID 0x00
#define SDATAC 0x11
uint8_t debug_msg = 1U;
字符串 Sep =------------------------------------------------------- ";
字符串 hex_to_char (int hex_in){
int precision = 2;
char tmp[16];
char format[128];
sprintf (format、"0x%.%DX"、 Precision);
sprintf (tmp、格式、hex_in);
//Serial.print (tmp);
return (String (tmp));
}
uint8_t read_Byte (uint8_t reg_addr)
{
uint8_t out = 0;
digitalWrite (PIN_CS、低电平);
spi.transfer (0x20 | reg_addr);
delayMicroseconds (5);
SPI.transfer (0x00);
delayMicroseconds (5);
OUT = SPI.transfer (0x00);
delayMicroseconds (1);
digitalWrite (PIN_CS、HIGH);
if (debug_msg)
{
serial.println (Sep);
serial.println ("sent:\t"+ hex_to_char (reg_addr));
serial.println (“接收到:\t"+ hex_to_char (out)));
}
return (out);
}
void send_command (uint8_t cmd)
{
digitalWrite (PIN_CS、低电平);
delayMicroseconds (5);// 5 = 6us (32时)
spi.transfer (cmd);
delayMicroseconds (10);
digitalWrite (PIN_CS,高电平);
}
void setup()
{
Serial.begin(9600);
引脚模式(CLK1、输出);
引脚模式(MISO1、输入);
引脚模式(MOSI1、输出);
PinMode (PIN_CS、输出);
引脚模式(PIN_RESET、输出);
引脚模式(PIN_START、输出);
引脚模式(PIN_DRDY、输入);
digitalWrite (PIN_CS、HIGH);
digitalWrite (PIN_START、LOW);
SPI.begin();
SPI.setDataMode(SPI_MODE1);
SPI.setClockDivider(SPI_CLOCK_DIV16);
SPI.setBitOrder(MSBFIRST);
延迟(1000);
digitalWrite (PIN_RESET、HIGH);
延迟(1000);
digitalWrite (PIN_RESET、LOW);
延迟(1000);
digitalWrite (PIN_RESET、HIGH);
延迟(100);
digitalWrite (PIN_CS、低电平);
延迟(1000);
digitalWrite (PIN_CS、HIGH);
延迟(1000);
SEND_COMMAND (SDATAC);
延迟(10);
for (;;)
{
uint8_t chSet = read_Byte (read | ID);
serial.print ("-- ID"+ String (chSet)+"-");
延迟(1000);
}
}
void loop()
{
}