从事使用二进制命令代码的 arduino 项目。
采样率和过滤器类型是连接的 2 个代码。采样率 = MSB 一半,滤波器类型 = LSB 一半。
发现:C中的按位连接
#include <stdio.h>
int main() {
int first = 0b1010;
//^^v See here
int second = 0b0011;
int result = (first << 4) | second;
printf("%d", result);
return 0;
它显示了如何连接两个二进制值并将它们相加。
.h file
在as 宏中包含所有二进制代码。我可以对纯二进制值做同样的事情吗?类型是什么?将使用连接的二进制值 - 作为函数中的命令。
所有宏:
//Sample Rate and Filter Type Codes From ADS1261 Datasheets
/*Binary Code Commands Defining Sampling Rate and Filter Type - http://www.ti.com/lit/ds/symlink/ads1261.pdf#page=61*/
//ADC DATA RATE
#define SPS_2_PT_5 0b00000 //SPS = 2.5
#define SPS_5 0b00001 //SPS = 5
#define SPS_10 0b00010 //SPS = 10
#define SPS_16_PT_6 0b00011 //SPS = 16.6
#define SPS_20_DEFAULT 0b00100 //SPS = 20 <--- this is also the default.
#define SPS_50 0b00101 //SPS = 50
#define SPS_60 0b00110 //SPS = 60
#define SPS_100 0b00111 //SPS = 100
#define SPS_400 0b01000 //SPS = 400
#define SPS_1200 0b01001 //SPS = 1200
#define SPS_2400 0b01010 //SPS = 2400
#define SPS_4800 0b01011 //SPS = 4800
#define SPS_7200 0b01100 //SPS = 7200
#define SPS_14400 0b01101 //SPS = 14400
#define SPS_19200 0b01110 //SPS = 19200
#define SPS_25600 0b00110 //SPS = 25600
#define SPS_40000 0b10000 //SPS (f_CLK - 10.24 MHz)
//Define Filter Types
#define F_SINC1 0b000 //SINC1
#define F_SINC2 0b001 //SINC2
#define F_SINC3 0b010 //SINC3
#define F_SINC4 0b011 //SINC4
#define F_FIR 0b100 //FIR// Default if not specified.