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
2ca4bfe4
Commit
2ca4bfe4
authored
Mar 14, 2016
by
Sandeep Mistry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
UART TX and RX
parent
821028a3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
8 deletions
+41
-8
cores/nRF52/Uart.cpp
cores/nRF52/Uart.cpp
+32
-4
cores/nRF52/Uart.h
cores/nRF52/Uart.h
+3
-1
variants/nRF52DK/variant.cpp
variants/nRF52DK/variant.cpp
+6
-3
No files found.
cores/nRF52/Uart.cpp
View file @
2ca4bfe4
...
@@ -20,9 +20,10 @@
...
@@ -20,9 +20,10 @@
#include "Arduino.h"
#include "Arduino.h"
#include "wiring_private.h"
#include "wiring_private.h"
Uart
::
Uart
(
NRF_UART_Type
*
_nrfUart
,
uint8_t
_pinRX
,
uint8_t
_pinTX
)
Uart
::
Uart
(
NRF_UART_Type
*
_nrfUart
,
IRQn_Type
_IRQn
,
uint8_t
_pinRX
,
uint8_t
_pinTX
)
{
{
nrfUart
=
_nrfUart
;
nrfUart
=
_nrfUart
;
IRQn
=
_IRQn
;
uc_pinRX
=
_pinRX
;
uc_pinRX
=
_pinRX
;
uc_pinTX
=
_pinTX
;
uc_pinTX
=
_pinTX
;
}
}
...
@@ -35,7 +36,7 @@ void Uart::begin(unsigned long baudrate)
...
@@ -35,7 +36,7 @@ void Uart::begin(unsigned long baudrate)
void
Uart
::
begin
(
unsigned
long
baudrate
,
uint16_t
/*config*/
)
void
Uart
::
begin
(
unsigned
long
baudrate
,
uint16_t
/*config*/
)
{
{
pinMode
(
uc_pinTX
,
OUTPUT
);
pinMode
(
uc_pinTX
,
OUTPUT
);
pinMode
(
uc_pinRX
,
INPUT
_PULLUP
);
pinMode
(
uc_pinRX
,
INPUT
);
nrf_uart_txrx_pins_set
(
nrfUart
,
uc_pinTX
,
uc_pinRX
);
nrf_uart_txrx_pins_set
(
nrfUart
,
uc_pinTX
,
uc_pinRX
);
nrf_uart_configure
(
nrfUart
,
NRF_UART_PARITY_EXCLUDED
,
NRF_UART_HWFC_DISABLED
);
nrf_uart_configure
(
nrfUart
,
NRF_UART_PARITY_EXCLUDED
,
NRF_UART_HWFC_DISABLED
);
...
@@ -80,13 +81,32 @@ void Uart::begin(unsigned long baudrate, uint16_t /*config*/)
...
@@ -80,13 +81,32 @@ void Uart::begin(unsigned long baudrate, uint16_t /*config*/)
nrf_uart_enable
(
nrfUart
);
nrf_uart_enable
(
nrfUart
);
nrf_uart_event_clear
(
nrfUart
,
NRF_UART_EVENT_RXDRDY
);
nrf_uart_event_clear
(
nrfUart
,
NRF_UART_EVENT_TXDRDY
);
nrf_uart_task_trigger
(
nrfUart
,
NRF_UART_TASK_STARTRX
);
nrf_uart_task_trigger
(
nrfUart
,
NRF_UART_TASK_STARTTX
);
nrf_uart_task_trigger
(
nrfUart
,
NRF_UART_TASK_STARTTX
);
nrf_uart_int_enable
(
nrfUart
,
NRF_UART_INT_MASK_RXDRDY
);
NVIC_ClearPendingIRQ
(
IRQn
);
NVIC_SetPriority
(
IRQn
,
3
);
NVIC_EnableIRQ
(
IRQn
);
}
}
void
Uart
::
end
()
void
Uart
::
end
()
{
{
nrf_uart_txrx_pins_disconnect
(
nrfUart
);
NVIC_DisableIRQ
(
IRQn
);
nrf_uart_int_disable
(
nrfUart
,
NRF_UART_INT_MASK_RXDRDY
);
nrf_uart_task_trigger
(
nrfUart
,
NRF_UART_TASK_STOPRX
);
nrf_uart_task_trigger
(
nrfUart
,
NRF_UART_TASK_STOPTX
);
nrf_uart_disable
(
nrfUart
);
nrf_uart_disable
(
nrfUart
);
nrf_uart_txrx_pins_disconnect
(
nrfUart
);
rxBuffer
.
clear
();
rxBuffer
.
clear
();
}
}
...
@@ -96,6 +116,12 @@ void Uart::flush()
...
@@ -96,6 +116,12 @@ void Uart::flush()
void
Uart
::
IrqHandler
()
void
Uart
::
IrqHandler
()
{
{
if
(
nrf_uart_event_check
(
nrfUart
,
NRF_UART_EVENT_RXDRDY
))
{
rxBuffer
.
store_char
(
nrf_uart_rxd_get
(
nrfUart
));
nrf_uart_event_clear
(
nrfUart
,
NRF_UART_EVENT_RXDRDY
);
}
}
}
int
Uart
::
available
()
int
Uart
::
available
()
...
@@ -117,7 +143,9 @@ size_t Uart::write(const uint8_t data)
...
@@ -117,7 +143,9 @@ size_t Uart::write(const uint8_t data)
{
{
nrf_uart_txd_set
(
nrfUart
,
data
);
nrf_uart_txd_set
(
nrfUart
,
data
);
delay
(
10
);
while
(
!
nrf_uart_event_check
(
nrfUart
,
NRF_UART_EVENT_TXDRDY
));
nrf_uart_event_clear
(
nrfUart
,
NRF_UART_EVENT_TXDRDY
);
return
1
;
return
1
;
}
}
cores/nRF52/Uart.h
View file @
2ca4bfe4
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
class
Uart
:
public
HardwareSerial
class
Uart
:
public
HardwareSerial
{
{
public:
public:
Uart
(
NRF_UART_Type
*
_nrfUart
,
uint8_t
_pinRX
,
uint8_t
_pinTX
);
Uart
(
NRF_UART_Type
*
_nrfUart
,
IRQn_Type
_IRQn
,
uint8_t
_pinRX
,
uint8_t
_pinTX
);
void
begin
(
unsigned
long
baudRate
);
void
begin
(
unsigned
long
baudRate
);
void
begin
(
unsigned
long
baudrate
,
uint16_t
config
);
void
begin
(
unsigned
long
baudrate
,
uint16_t
config
);
void
end
();
void
end
();
...
@@ -46,6 +46,8 @@ class Uart : public HardwareSerial
...
@@ -46,6 +46,8 @@ class Uart : public HardwareSerial
NRF_UART_Type
*
nrfUart
;
NRF_UART_Type
*
nrfUart
;
RingBuffer
rxBuffer
;
RingBuffer
rxBuffer
;
IRQn_Type
IRQn
;
uint8_t
uc_pinRX
;
uint8_t
uc_pinRX
;
uint8_t
uc_pinTX
;
uint8_t
uc_pinTX
;
};
};
variants/nRF52DK/variant.cpp
View file @
2ca4bfe4
...
@@ -18,9 +18,12 @@
...
@@ -18,9 +18,12 @@
#include "variant.h"
#include "variant.h"
Uart
Serial
(
NRF_UART0
,
RX_PIN_NUMBER
,
TX_PIN_NUMBER
);
Uart
Serial
(
NRF_UART0
,
UARTE0_UART0_IRQn
,
RX_PIN_NUMBER
,
TX_PIN_NUMBER
);
void
UARTE0_UART0_IRQHandler
()
extern
"C"
{
{
Serial
.
IrqHandler
();
void
UARTE0_UART0_IRQHandler
()
{
Serial
.
IrqHandler
();
}
}
}
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