Converting code for micro:bit v1 (nRF51822) to micro:bit v2 (nRF52833) with the focus on UART

2313.2_uart.zip

Hello,

I am a research assistant at the Norwegian University of Science and Technology. We have in the past been using the micro:bit v1 for our practical labs which purpose is to introduce the students to basic C programming. For that, we have been using GCC ARM as our compiler, nrfjprog to flash compiled code to the micro:bit, and lastly JLink to communicate with the micro:bit. The latter removes the DAL by just simply drag and drop of the hex file from Segger.com.

Our problem is that for this year, we have received the second version of the micro:bit, which uses a nrf52833. I was therefore wondering if there is someone who could help me on the way to replicate the simple assignments that we have earlier created for the v1 for the new v2? Jørgen Holmefjord has already been of great help with setting up the environment but I have some issues with coding some of the registers. More specifically the UART module (see the zip file I attached). What I want to code is a two ways communication with the micro:bit v2 using picocom, where if I press the B button, the micro:bit sends "Button" + "B" and turn the led lights on, while when I press the A button, the micro:bit sends "Button" + "A" and turning the led lights off. Additionally, I also tried to program the micro:bit such that an external keyboard input will turn on and off the led lights depending on the state of the led lights.

My current progress which is found in the zip file manages to connect the GPIO module to the lights and the buttons. The resulting code when flashed over turns on and off the light depending on the button, but it does not seem to be able to communicate via UART. I suspect I maybe misunderstood the UART module?

Thank you so much in advance,

Best wishes,

Kiet

  • Hi Kiet,

    I suspect there is a problem with your pin configuration for the UART peripheral. In the code you uploaded, it seems that it is set to the following:

    	UART->PSELRXD = 0x26; // 0b100110 pin select 6, port 0, connected
    	UART->PSELTXD = 0x28; // 0b101000 pin select 8, port 1, connected

    This corresponds to P1.06 and P1.08, not P0.06 and P1.08, as the pinmap indicates. You should change the first line to:

    	UART->PSELRXD = 0x06; // 0b000110 pin select 6, port 0, connected

    I also suspect that the RX and TX pins should be swapped. The Micro:bit v2 pinmap indicates that P0.06 on nRF52833 is connected to LPUART1_RX on the interface MCU, and that P1.08 on nRF52833 is connected to LPUART1_TX on the interface MCU. Remember that UART should have cross-connections between TX and RX on each chip. This is also the configuration implemented by default in nRF Connect SDK/Zephyr RTOS. My suggestion would then be to test with the following code:

    	UART->PSELRXD = 0x28; // 0b101000 pin select 8, port 1, connected
    	UART->PSELTXD = 0x06; // 0b000110 pin select 6, port 0, connected

    Best regards,
    Jørgen

Related