This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

nRF52 Software Serial library similar to Arduino software serial

I have made a software serial library for nRF52840 similar to Arduino software serial. It is working fine. nRF52840 has two UARTE instance and one UART instance, As for my application requirement I need 3 UART or UARTE instances. 

Working baud rates: 1200, 2400, 4800, 9600, 14400, 19200, 28800, 31250, 38400, 56000, 57600, 76800,

Not working rates : 115200 

Count  of UART instances:  4. You can increase the number of instances by doing some minor modification in the software.

Test: I have only tested one SF_UART. It is working fine.

Can you help me to improve this library? I want to use 115200 baud rate, which is not working yet. 

All community members can use this library if they are lacking hardware UART. Please help me to improve it more. keep sharing more updates.

sf_uart.h
gpio.h

Parents
  • Hi,

    What is not working with 115200 baudrate? I tried your code, but I got hardfault in gpiote_drvInEventhandler(), is there some code missing?

    Handling 115200 baudrate in software will be quite work-intensive for the CPU to handle all the interrupts. You may need to consider writing your own GPIOTE interrupt handler for this specific purpose, to reduce the overhead of the generic checks that is performed in the GPIOTE driver. An optimized interrupt handler that is doing only what is required, may help resolve your issues.

    Note that SW/bit-banging UART will not work well together with BLE or other high-priority interrupt tasks, as this will block you from keeping the timing requirements of the UART reading/writing.

    Best regards,
    Jørgen

Reply
  • Hi,

    What is not working with 115200 baudrate? I tried your code, but I got hardfault in gpiote_drvInEventhandler(), is there some code missing?

    Handling 115200 baudrate in software will be quite work-intensive for the CPU to handle all the interrupts. You may need to consider writing your own GPIOTE interrupt handler for this specific purpose, to reduce the overhead of the generic checks that is performed in the GPIOTE driver. An optimized interrupt handler that is doing only what is required, may help resolve your issues.

    Note that SW/bit-banging UART will not work well together with BLE or other high-priority interrupt tasks, as this will block you from keeping the timing requirements of the UART reading/writing.

    Best regards,
    Jørgen

Children
  • what are the connections?

  • Used your exact code/files, connected P1.10 to P1.11. It HardFaults at gpio.c:130.

    Built using SES for pca10056/nRF52840 target.

  • Okay. Jorgen, it will not work with this connection. Please use hardware UART or UARTE with it for testing. 

  • Ok, seems it is working when connected with the J-Link VCOM on the DK at 9600 baudrate.

    Looks like the optimization level affects the timing enough to break it at higher baudrate levels though. 57600/76800 is unstable or not working correctly with optimization set to anything below level 3 during my testing. Once I was actually able to receive data correctly with application baudrate set to 76800 and terminal set to 57600.

    115200 baudrate is also working for TX with optimization level set to 3 on my end, but RX is not working correctly. However, it seems is just 1 bit off the expected, so you may have to check if there is some way you can resolve it:

    Expected:"H": 0x48 -> 0xC8, "E": 0x45 -> 0xC5, "L": 0x4C -> 0xCC, "O": 0x4F -> 0xCF, "h": 0x68 -> 0xE8, "e": 0x65 -> 0xE5, "l": 0x6C -> 0xEC, "o": 0x6F -> 0xEF.