Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-nRF5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-nRF5
Commits
3196bfb9
Commit
3196bfb9
authored
Apr 06, 2017
by
carlosperate
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix nRF51 I2C read operation
parent
8747fa2d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
15 deletions
+23
-15
libraries/Wire/Wire.h
libraries/Wire/Wire.h
+2
-4
libraries/Wire/Wire_nRF51.cpp
libraries/Wire/Wire_nRF51.cpp
+21
-11
No files found.
libraries/Wire/Wire.h
View file @
3196bfb9
...
...
@@ -28,9 +28,7 @@
#include "RingBuffer.h"
#define BUFFER_LENGTH 32
// WIRE_HAS_END means Wire has end()
// WIRE_HAS_END means Wire has end()
#define WIRE_HAS_END 1
class
TwoWire
:
public
Stream
...
...
@@ -91,7 +89,7 @@ class TwoWire : public Stream
// RX Buffer
RingBuffer
rxBuffer
;
//TX buffer
//
TX buffer
RingBuffer
txBuffer
;
uint8_t
txAddress
;
...
...
libraries/Wire/Wire_nRF51.cpp
View file @
3196bfb9
...
...
@@ -36,7 +36,7 @@ TwoWire::TwoWire(NRF_TWI_Type * p_twi, IRQn_Type IRQn, uint8_t pinSDA, uint8_t p
this
->
_IRQn
=
IRQn
;
this
->
_uc_pinSDA
=
g_ADigitalPinMap
[
pinSDA
];
this
->
_uc_pinSCL
=
g_ADigitalPinMap
[
pinSCL
];
transmissionBegun
=
false
;
t
his
->
t
ransmissionBegun
=
false
;
}
void
TwoWire
::
begin
(
void
)
{
...
...
@@ -55,7 +55,7 @@ void TwoWire::begin(void) {
|
((
uint32_t
)
GPIO_PIN_CNF_DRIVE_S0D1
<<
GPIO_PIN_CNF_DRIVE_Pos
)
|
((
uint32_t
)
GPIO_PIN_CNF_SENSE_Disabled
<<
GPIO_PIN_CNF_SENSE_Pos
);
_p_twi
->
FREQUENCY
=
TWI_FREQUENCY_FREQUENCY_K100
;
_p_twi
->
FREQUENCY
=
(
TWI_FREQUENCY_FREQUENCY_K100
<<
TWI_FREQUENCY_FREQUENCY_Pos
)
;
_p_twi
->
ENABLE
=
(
TWI_ENABLE_ENABLE_Enabled
<<
TWI_ENABLE_ENABLE_Pos
);
_p_twi
->
PSELSCL
=
_uc_pinSCL
;
_p_twi
->
PSELSDA
=
_uc_pinSDA
;
...
...
@@ -83,7 +83,7 @@ void TwoWire::setClock(uint32_t baudrate) {
frequency
=
TWI_FREQUENCY_FREQUENCY_K400
;
}
_p_twi
->
FREQUENCY
=
frequency
;
_p_twi
->
FREQUENCY
=
(
frequency
<<
TWI_FREQUENCY_FREQUENCY_Pos
)
;
_p_twi
->
ENABLE
=
(
TWI_ENABLE_ENABLE_Enabled
<<
TWI_ENABLE_ENABLE_Pos
);
}
...
...
@@ -93,22 +93,34 @@ void TwoWire::end() {
uint8_t
TwoWire
::
requestFrom
(
uint8_t
address
,
size_t
quantity
,
bool
stopBit
)
{
if
(
quantity
==
0
)
if
(
quantity
==
0
)
{
return
0
;
}
if
(
quantity
>
SERIAL_BUFFER_SIZE
)
{
quantity
=
SERIAL_BUFFER_SIZE
;
}
size_t
byteRead
=
0
;
rxBuffer
.
clear
();
_p_twi
->
ADDRESS
=
address
;
_p_twi
->
SHORTS
=
0x1UL
;
// To trigger suspend task when a byte is received
_p_twi
->
TASKS_RESUME
=
0x1UL
;
_p_twi
->
TASKS_STARTRX
=
0x1UL
;
for
(
size_t
i
=
0
;
i
<
quantity
;
i
++
)
for
(
byteRead
=
0
;
byteRead
<
quantity
;
byteRead
++
)
{
while
(
!
_p_twi
->
EVENTS_RXDREADY
&&
!
_p_twi
->
EVENTS_ERROR
);
if
(
byteRead
==
quantity
-
1
)
{
// To trigger stop task when last byte is received, set before resume task.
_p_twi
->
SHORTS
=
0x2UL
;
}
_p_twi
->
TASKS_RESUME
=
0x1UL
;
while
(
!
_p_twi
->
EVENTS_RXDREADY
&&
!
_p_twi
->
EVENTS_ERROR
);
if
(
_p_twi
->
EVENTS_ERROR
)
{
...
...
@@ -118,8 +130,6 @@ uint8_t TwoWire::requestFrom(uint8_t address, size_t quantity, bool stopBit)
_p_twi
->
EVENTS_RXDREADY
=
0x0UL
;
rxBuffer
.
store_char
(
_p_twi
->
RXD
);
_p_twi
->
TASKS_RESUME
=
0x1UL
;
}
if
(
stopBit
||
_p_twi
->
EVENTS_ERROR
)
...
...
@@ -164,11 +174,11 @@ void TwoWire::beginTransmission(uint8_t address) {
// 4 : Other error
uint8_t
TwoWire
::
endTransmission
(
bool
stopBit
)
{
transmissionBegun
=
false
;
transmissionBegun
=
false
;
// Start I2C transmission
_p_twi
->
ADDRESS
=
txAddress
;
_p_twi
->
SHORTS
=
0x0UL
;
_p_twi
->
TASKS_RESUME
=
0x1UL
;
_p_twi
->
TASKS_STARTTX
=
0x1UL
;
...
...
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