Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support NRF52 / Arduino Nano 33 BLE #58

Open
kallaspriit opened this issue Jul 9, 2022 · 2 comments
Open

Support NRF52 / Arduino Nano 33 BLE #58

kallaspriit opened this issue Jul 9, 2022 · 2 comments

Comments

@kallaspriit
Copy link

Found a way to get the library to work on the Arduino Nano 33 BLE.

By default the UART on the NRF52 does not support custom baud rates or UART config other than the default but these can be configured using registers.

Basically I did something like this:

At the start of sbus.cpp after the includes:

#if defined(ARDUINO_ARCH_NRF52840) // Arduino Nano 33 BLE

#define UARTE0_BASE_ADDR 0x40002000
#define UARTE1_BASE_ADDR 0x40028000
#define UART_BAUDRATE_REG_OFFSET 0x524
#define UART_CONFIG_REG_OFFSET 0x56C
#define UART_CONFIG_8E2 0x000000F
#define UART_BAUD_100000 0x19114A7
#define UART0_BAUDRATE_REGISTER (((unsigned int *)(UARTE0_BASE_ADDR + UART_BAUDRATE_REG_OFFSET)))
#define UART1_BAUDRATE_REGISTER (((unsigned int *)(UARTE1_BASE_ADDR + UART_BAUDRATE_REG_OFFSET)))
#define UART0_CONFIG_REGISTER (((unsigned int *)(UARTE0_BASE_ADDR + UART_CONFIG_REG_OFFSET)))
#define UART1_CONFIG_REGISTER (((unsigned int *)(UARTE1_BASE_ADDR + UART_CONFIG_REG_OFFSET)))

#endif

Added custom Begin signature for the NRF52840 to support both UART0 and UART1:

#elif defined(ARDUINO_ARCH_NRF52840)
    void Begin(int uart = 0);
#else

And then added custom initialization in Begin:

#elif defined(ARDUINO_ARCH_NRF52840) // Arduino Nano 33 BLE
  uart_->begin(9600);

  if (uart == 0)
  {
    *UART0_BAUDRATE_REGISTER = UART_BAUD_100000;
    *UART0_CONFIG_REGISTER = UART_CONFIG_8E2;
  }
  else if (uart == 1)
  {
    *UART1_BAUDRATE_REGISTER = UART_BAUD_100000;
    *UART1_CONFIG_REGISTER = UART_CONFIG_8E2;
  }
/* Everything else, with a hardware inverter */
#else

The same could be done for SbusTx.

Tested with Frsky R-XSR using the uninverted sbus signal from the B-pad and it works great.

image

Would be cool if this support was included in the library and if not then maybe it helps someone who finds this issue :)

@flybrianfly
Copy link
Contributor

I'm sorry, I was on travel when you sent this and it must have slipped past my radar. I'd like to implement this - is it possible to implement an inverted serial on the Nano? Does it only have two Serial ports or are there more to support? Would you be willing to test versions of the library that add support? I'm not very familiar with that platform.

@kallaspriit
Copy link
Author

Not sure about inverted but I could test the uninverted implementation. You could also pick up the board for testing, they're not expensive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants