Softwareserial and rc interrupts are conflicting


I am working with quadcopter project ,here i am using a mcu called Hifive1(risc-v core) arduino compatible.
I have completed the project with RC and it is now flying and now i want to add GPS (neo 6m) to make it as an autonomous one.
As my controller doesn't have hardware uart, a library called "Softwareserial32" similar to Softwareserial ,is being used for serial communication between the gps and mcu.
Unfortunately the Interrupts for Remote control and Softwareserial32 library isr are conflicting as the library have used noInterrupts() & interrupts() function in many places ,that stops the interrupts for a long time.

Library link for reference.

I need a guidance for my problem.

You can run RC servos without using interrupts. Set up a 18ms timer. Every time it fires off, send the pulses to the servos.

-jim lee

But how will i control the quadcopter without RC?
It should be a multipurpose one ,i can control with RC as well and if i switch on the channel 5th stick it will get the value of the channel(if it is 1500) , the LAT and LONG from the gps is noted and it will hover at that particular location.
So interrupt is required for RC i guess.

You could wire a UART chip to your MCU.

You didn't write the RC code, did you?

You could wire a UART chip to your MCU.

You didn't write the RC code, did you?

I will look on it.

Yes i have written the code.I just took a reference from joop brokking code and modified according to my micro controller, The Quadcopter now runs with RC.
The next step is to add gps module to it.

And is there any reference sample code or working and wiring procedure of UART ic available?

Use components with SPI or I2C connection instead of UART. Or a controller with multiple UARTs in hardware.

My controller has hardware spi, So is it possible to communicate with gps module by using any spi to uart bridge? Anything available?
Because i cant change the controller.

Change the gps module, if required, not the controller. Which module do you use?

How about using this one?

Look into AltSoftSerial. It uses a different interrupt, one that's not normally used, and it uses a 16-bit timer (that'd be timer1 on the ATmega328p).

ATmega48 and 88 are low-end 328 family that have SPI and UART. ATtiny chips have USI instead of UART.

ATmega48 and 88 are low-end 328 family that have SPI and UART. ATtiny chips have USI instead of UART.

It seems I'm not the only one that missed the OP using a non-AVR processor...

Annnnnd you missed that that MCU has SPI and that a low-end AVR could bridge SPI to UART and possibly help process the data.

It’s not far-fetched. The chip doesn’t need a clock to run at 8MHz; just a couple of bypass caps, power, ground, reset can be turned off and the rest is wire up SPI and RX/TX.

ATmegas have the features to be Swiss Army Glue Chips. Step 1 is get out of the box.

I wasn't thinking to add more hardware than necessary... especially on a quadcopter where every gram counts. But of course,it's definitely a possible solution.

The chip and bypass caps do weigh more than a gram. If a socket is used to keep from soldering to DIP pins then there’s a bit more.

This is to get SPI<–>UART, it’s cheaper and lighter than much of what I saw online. It can also do more than simply SPI<–>UART.

So,shall i go with that spi to uart bridge and take it as a conclusion based on the conversation? And Hifive1 is a non-AVR processor.

SPI is a standard bus, you may have to set the Hifive SPI clock divider to more than default.

ATmega328 is used on Uno/Nano/Mini. The ATmega168 was on the pre-Uno Duemilanove, has 1K RAM for more buffer space.

Arduino code for SPI master and slave with explanations is here:

This tutorial can get you started on running AVR chips standalone. Arduino board becomes the chip programmer.

With SPI there is a buffer, perhaps the 168 or 328 would be a better choice than an 88.

Connected to the Hifive SPI the AVR is just a device except that you control how this one runs.

Even with the AVR at 8MHz, 115200 serial baud rate bytes arrive 694 cycles apart. The chip has time to translate SPI binary data to serial text and versa. The AVR chip may be rated to 20MHz with a crystal, I have a 1284P that runs 24MHz.

Once you have SPI bus you can also connect SD to write a log to. Start every new line with millis in hex, it helps tracing down errors/bugs. Close the file after writing every line to update the FAT and reopen the file as append.

OTOH after looking Hifive1 up, it's got BT and Wifi serial.

Actually i am using Hifive1 version 1, i forgot to give the info

Hifive1 Rev B is what you told about, that has BT and Wifi serial

Ok, then coming to the point, this is what i understood from your previous reply and correct me if i am wrong.

SPI Softwareserial(uart)
Hifive1 <------------->Arduino328(chip)<--------------------------> GPS

That is it.

SPI Softwareserial(uart)
Hifive1 <------------->Arduino328(chip)<--------------------------> GPS

and maybe add SD to the SPI bus.

But you might find a GPS with SPI or I2C interface, need no translator.

From the spec I was looking for what OS’s it runs, like an RPi, but no, your code owns the board.

Another solution is to write code for RC that does not depend on an interrupt. Just how close does the timing have to be? Would 20 microseconds late be acceptable? AVR-duino interrupt has > 5 us overhead.

I will give you a small details about the RC

The receiver that i am using is r6b, it doesn't have ppm output, So, i used arduino pro min as a pwm to ppm converter.

you can see the entire details over here.Bain page: PWM to PPM converter for the Flysky R6B receiver.

In hifive1 controller pin17 is my ppm pin as input and initialized as attachInterrupt(ppmPin,Isr,RISING) and the isr are also made.

ppm signal has a series of pulses of fixed length, here the length is 100us.

And in my main loop of rc code , the execution time is 4ms (so with in 4ms all the calculations are made)
So it is known that 250Hz is the refresh rate of the quadcopter.

You can also check the arduino SPI library implementations for hifive1 controller over here