Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
osie
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
osie
Commits
e0c9a92a
Commit
e0c9a92a
authored
Feb 22, 2022
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Since ADC is 10 bit we need to read and handle two bytes not just one.
parent
b0105f3a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
12 deletions
+7
-12
coupler/opc-ua-server/server.c
coupler/opc-ua-server/server.c
+7
-12
No files found.
coupler/opc-ua-server/server.c
View file @
e0c9a92a
...
...
@@ -264,25 +264,20 @@ static int getAnalogInputStateAIN(int i2c_addr, int **analog_input, uint8_t read
/* ERROR HANDLING: i2c transaction failed */
printf
(
"Error writing to i2c slave (0x%x).
\n
"
,
i2c_addr
);
}
if
(
read
(
file
,
read_buf
,
1
)
!=
1
)
if
(
read
(
file
,
read_buf
,
2
)
!=
2
)
{
/* ERROR HANDLING: i2c transaction failed */
printf
(
"Error reading analog input from i2c slave (0x%x).
\n
"
,
i2c_addr
);
}
else
{
/* Since read_buf[0] is (LSB:MSB) we need to convert it to (MSB:LSB). To swap bits one by one do
the following */
int
analog_data
=
0
;
for
(
int
index
=
0
;
index
<
8
;
index
++
)
{
analog_data
|=
((
read_buf
[
0
]
&
0x80
)
?
1
:
0
)
<<
index
;
read_buf
[
0
]
<<=
1
;
}
/* Now add the high 2 bit to the value */
analog_data
|=
((
read_buf
[
1
]
&
0x02
)
?
1
:
0
)
<<
8
;
analog_data
|=
((
read_buf
[
1
]
&
0x01
)
?
1
:
0
)
<<
9
;
*
analog_input
=
&
analog_data
;
// based on https://github.com/OLIMEX/OLINUXINO/blob/master/SOFTWARE/A13/MOD-IO/main.c
// since ADC is 10 bit we need to read and convert accordingly 2 bytes
analog_data
=
read_buf
[
1
];
analog_data
<<=
8
;
analog_data
|=
read_buf
[
0
];
*
analog_input
=
&
analog_data
;
}
close
(
file
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment