Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RBComb Temperature Control
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pascal Engeler
RBComb Temperature Control
Commits
6cd6c75a
Commit
6cd6c75a
authored
2 years ago
by
Pascal Engeler
Browse files
Options
Downloads
Patches
Plain Diff
Communication works, turn on reference, expose clk
parent
f9e65d21
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
firmware/playground/playground.ino
+80
-5
80 additions, 5 deletions
firmware/playground/playground.ino
with
80 additions
and
5 deletions
firmware/playground/playground.ino
+
80
−
5
View file @
6cd6c75a
#include
<SPI.h>
#define nCS 46
#define REG_ID 0x05
#define REG_READ 0b01000000
#define REG_WRITE 0b00000000
#define REG_ADC_CONTROL 0x01
#define POWER_MODE_FULLPOWER 0b0000000010000000
#define CLK_SEL_INTERNALANDPIN 0b0000000000000001
#define REF_EN 0b0000000100000000
void
reset_comm
(){
SPI
.
beginTransaction
(
SPISettings
(
84000000
/
128
,
MSBFIRST
,
SPI_MODE3
));
for
(
unsigned
i
=
0
;
i
<
8
;
++
i
){
SPI
.
transfer
(
0xFF
);
}
SPI
.
endTransaction
();
}
//T must be either uint8_t, uint16_t or uint24_t
template
<
class
T
>
void
SPIwrite
(
T
data
,
uint8_t
reg
){
uint8_t
wrbuf
[]
=
{
0
,
0
,
0
,
0
};
//set up write command
wrbuf
[
0
]
=
reg
|
REG_WRITE
;
uint8_t
num_bytes
=
sizeof
(
data
);
for
(
unsigned
i
=
0
;
i
<
num_bytes
;
++
i
){
wrbuf
[
num_bytes
-
i
]
=
data
&
0xFF
;
data
>>=
8
;
}
SPI
.
beginTransaction
(
SPISettings
(
84000000
/
128
,
MSBFIRST
,
SPI_MODE3
));
SPI
.
transfer
(
wrbuf
,
num_bytes
+
1
);
SPI
.
endTransaction
();
}
//T must be either uint8_t, uint16_t or uint24_t
template
<
class
T
>
void
SPIread
(
T
&
data
,
uint8_t
reg
){
uint8_t
rdbuf
[]
=
{
0
,
0
,
0
,
0
};
//set up write command
rdbuf
[
0
]
=
reg
|
REG_READ
;
uint8_t
num_bytes
=
sizeof
(
data
);
SPI
.
beginTransaction
(
SPISettings
(
84000000
/
128
,
MSBFIRST
,
SPI_MODE3
));
SPI
.
transfer
(
rdbuf
,
num_bytes
+
1
);
SPI
.
endTransaction
();
for
(
unsigned
i
=
1
;
i
<=
num_bytes
;
++
i
){
data
<<=
8
;
data
+=
rdbuf
[
i
];
}
}
void
setup
()
{
Serial
.
begin
(
9600
);
digitalWrite
(
nCS
,
HIGH
);
pinMode
(
nCS
,
OUTPUT
);
SPI
.
begin
();
delay
(
1000
);
digitalWrite
(
nCS
,
LOW
);
uint16_t
data
;
SPIread
(
data
,
REG_ADC_CONTROL
);
Serial
.
print
(
"ADC_CONTROL: "
);
Serial
.
print
(
data
,
BIN
);
Serial
.
print
(
"
\n
"
);
//Turn on internal reference, expose MCLK
data
|=
CLK_SEL_INTERNALANDPIN
|
REF_EN
;
Serial
.
print
(
"Setting to "
);
Serial
.
print
(
data
,
BIN
);
Serial
.
print
(
"
\n
"
);
SPIwrite
(
data
,
REG_ADC_CONTROL
);
//Read ADC_CONTROL
SPIread
(
data
,
REG_ADC_CONTROL
);
Serial
.
print
(
"ADC_CONTROL: "
);
Serial
.
print
(
data
,
BIN
);
Serial
.
print
(
"
\n
"
);
digitalWrite
(
nCS
,
HIGH
);
}
void
loop
()
{
SPI
.
beginTransaction
(
SPISettings
(
84000000
/
128
,
MSBFIRST
,
SPI_MODE3
));
digitalWrite
(
nCS
,
LOW
);
SPI
.
transfer
(
REG_ID
|
REG_READ
)
;
uint8_t
id
=
SPI
.
transfer
(
0x00
);
uint8_t
id
;
SPIread
(
id
,
REG_ID
);
digitalWrite
(
nCS
,
HIGH
);
S
PI
.
endTransaction
(
);
Serial
.
print
(
id
,
HEX
);
S
erial
.
print
(
id
,
BIN
);
Serial
.
print
(
"
\n
"
);
delay
(
1000
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment