Hello everyone!
I'm working on a hobby project and one of my goals is to read hobby RC reciever. It sends a PWM pulse to specific pin for each channel. I got the code working perfect when it was all in one file (main.c). But sice it's more organised to have more files, I decided to seperate functions for reading signal, functions that take care of time ( all od these are interrupts) into RX.c and Time.c .
And now the problem occurs. All of the sudden nothing works anymore. The code is the same as it was before. So I had to add function that returns the current time ( micros() )
RX.c :
#include "Time.h"
#include "RX.h"
void RXChannel(){
IntStatus = GPIOIntStatus(GPIO_PORTA_BASE, true); // GET INTERRUPT STATUS ( ON WHICH PINS INTERRUPT HAPPENED)
GPIOIntClear(GPIO_PORTA_BASE, IntStatus); // CLEAR INT FLAG
//long long x = micros();
/////////// AUX1 ///////////////
if((IntStatus & GPIO_INT_PIN_5) == GPIO_INT_PIN_5) // DID INTERRUPT OCCURED ON PIN A5?
{
value = GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_5);
if(value == GPIO_PIN_5) // IS PIN A5 HIGH?
{
RisingEdge1 = micros();
}
else if(value == 0) // IS PIN LOW?
{
uint32_t i = micros();
AUX1 = i - RisingEdge1;
}
}
}
And time.c :
static volatile uint32_t microsec;
static void SysTickIntHandler(void){
microsec++;
}
void Delay(uint32_t delay){
volatile long i = microsec;
while((microsec-i) < delay);
}
void initTime()
{
SysTickPeriodSet(79);
SysTickIntRegister(SysTickIntHandler);
SysTickIntEnable();
SysTickEnable();
}
uint32_t micros(void) {
return microsec;
}
After hours of debugging, I forgot to turn on transmitter ( so, if transmitter is off, reciever should not send any signal to pins) and I realized that code still acts as the signal has been recieved. All IF statements passed. I am realy desperate here, so any help would be appriciated.
Thanks!
Regards, Kristjan