vsdip / vsdsquadron_pio

Apache License 2.0
4 stars 2 forks source link

Unable to interface nrf24l01 PA LNA module with VSD Squadron Mini #19

Open Nahusha-Karnam opened 4 months ago

Nahusha-Karnam commented 4 months ago

I've built a flight controller with arduino nano and nrf24l01 PA LNA module this is the code for reciever

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>

int ch_1 = 0;
int ch_2 = 150;
int ch_3 = 150;
int ch_4 = 150;
int ch_5 = 0;
int ch_6 = 0;

Servo ch1;
Servo ch2;
Servo ch3;
Servo ch4;
Servo ch5;
Servo ch6;

struct Signal {
byte throttle;      
byte pitch;
byte roll;
byte yaw;
byte aux1;
byte aux2;
};

Signal data;

const uint64_t pipeIn = 0xE9E8F0F0E1LL;
RF24 radio(2, 3); 

void ResetData()
{
  data.throttle = 100;   
  data.pitch = 150;   
  data.roll = 150;     
  data.yaw = 150;     
  data.aux1 = 0;   
  data.aux2 = 0; 
}

void setup()
{
  //Set the pins for each PWM signal 
  ch1.attach(A0);
  ch2.attach(8);
  ch3.attach(7);
  ch4.attach(6);

  //Configure the NRF24 module
  ResetData();
  radio.begin();
  radio.openReadingPipe(1,pipeIn);
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening(); //start the radio comunication for receiver
  Serial.begin(9600);

}
unsigned long lastRecvTime = 0;

void recvData()
{
while ( radio.available() ) {
radio.read(&data, sizeof(Signal));
lastRecvTime = millis(); 
  }
    }
void loop()
{
recvData();
unsigned long now = millis();
if ( now - lastRecvTime > 1000 ) {
ResetData(); 
}
ch_1 = data.throttle;     // pin D5 (PWM signal)
ch_2 = data.pitch;     // pin D3 (PWM signal)
ch_3 = data.roll;     // pin D4 (PWM signal)
ch_4 = data.yaw;    // pin D2 (PWM signal)

ch_5 = data.aux1;     // pin D6 (PWM signal)
ch_6 = data.aux2;     // pin D7 (PWM signal)

ch1.writeMicroseconds(ch_1*10);
ch2.writeMicroseconds(ch_2*10);
ch3.writeMicroseconds(ch_3*10);
ch4.writeMicroseconds(ch_4*10);
Serial.println(ch_1);

}

I tried to compile this code in arduino IDE, i had uploaded other codes before it worked, but i am uploading this code with CH32V00x selected, and when i tried i had issues with Servo.h library and then i removed it as i can write that library on my own, but i had other problems removing servo.h library this is the code that i tried to compile

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int ch_1 = 0;
int ch_2 = 150;
int ch_3 = 150;
int ch_4 = 150;
int ch_5 = 0;
int ch_6 = 0;

struct Signal {
byte throttle;      
byte pitch;
byte roll;
byte yaw;
byte aux1;
byte aux2;
};

Signal data;

const uint64_t pipeIn = 0xE9E8F0F0E1LL;
RF24 radio(PC3, PC4);
void ResetData()
{
  data.throttle = 100;   // Motor stop | Motor Kapalı (Signal lost position | sinyal kesildiğindeki pozisyon)
  data.pitch = 150;    // Center | Merkez (Signal lost position | sinyal kesildiğindeki pozisyon)
  data.roll = 150;     // Center | merkez (Signal lost position | sinyal kesildiğindeki pozisyon)
  data.yaw = 150;     // Center | merkez (Signal lost position | sinyal kesildiğindeki pozisyon)
  data.aux1 = 0;    // Center | merkez (Signal lost position | sinyal kesildiğindeki pozisyon)
  data.aux2 = 0; // Center | Merkez
}

void setup()
{
  //Set the pins for each PWM signal | Her bir PWM sinyal için pinler belirleniyor.

  //Configure the NRF24 module
  ResetData();
  radio.begin();
  radio.openReadingPipe(1,pipeIn);
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening(); //start the radio comunication for receiver | Alıcı olarak sinyal iletişimi başlatılıyor
  Serial.begin(9600);

}
unsigned long lastRecvTime = 0;

void recvData()
{
while ( radio.available() ) {
radio.read(&data, sizeof(Signal));
lastRecvTime = millis(); 
  }
    }
void loop()
{
recvData();
unsigned long now = millis();
if ( now - lastRecvTime > 1000 ) {
ResetData(); 
}
ch_1 = data.throttle;     // pin D5 (PWM signal)
ch_2 = data.pitch;     // pin D3 (PWM signal)
ch_3 = data.roll;     // pin D4 (PWM signal)
ch_4 = data.yaw;    // pin D2 (PWM signal)

ch_5 = data.aux1;     // pin D6 (PWM signal)
ch_6 = data.aux2;     // pin D7 (PWM signal)
Serial.println(ch_1);

}

This is the error i am getting

c:/users/nahusha k l/appdata/local/arduino15/packages/wch/tools/riscv-none-embed-gcc/8.2.0/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: C:\Users\Nahusha K L\AppData\Local\Temp\arduino\sketches\F0EDEFF8107ABDC30CDEFF5A9237033F/rcv_vsd.ino.elf section `.text' will not fit in region `FLASH'
c:/users/nahusha k l/appdata/local/arduino15/packages/wch/tools/riscv-none-embed-gcc/8.2.0/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: region `FLASH' overflowed by 1504 bytes
c:/users/nahusha k l/appdata/local/arduino15/packages/wch/tools/riscv-none-embed-gcc/8.2.0/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: C:\Users\Nahusha K L\AppData\Local\Temp\arduino\sketches\F0EDEFF8107ABDC30CDEFF5A9237033F\libraries\SPI\utility\spi_com.c.o: in function `spi_init':
spi_com.c:(.text.spi_init+0x10): undefined reference to `PinMap_SPI_MOSI'
c:/users/nahusha k l/appdata/local/arduino15/packages/wch/tools/riscv-none-embed-gcc/8.2.0/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: spi_com.c:(.text.spi_init+0x16): undefined reference to `PinMap_SPI_MOSI'
c:/users/nahusha k l/appdata/local/arduino15/packages/wch/tools/riscv-none-embed-gcc/8.2.0/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: spi_com.c:(.text.spi_init+0x26): undefined reference to `PinMap_SPI_MISO'
c:/users/nahusha k l/appdata/local/arduino15/packages/wch/tools/riscv-none-embed-gcc/8.2.0/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: spi_com.c:(.text.spi_init+0x2a): undefined reference to `PinMap_SPI_MISO'
c:/users/nahusha k l/appdata/local/arduino15/packages/wch/tools/riscv-none-embed-gcc/8.2.0/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: spi_com.c:(.text.spi_init+0x36): undefined reference to `PinMap_SPI_SCLK'
c:/users/nahusha k l/appdata/local/arduino15/packages/wch/tools/riscv-none-embed-gcc/8.2.0/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: spi_com.c:(.text.spi_init+0x3a): undefined reference to `PinMap_SPI_SCLK'
c:/users/nahusha k l/appdata/local/arduino15/packages/wch/tools/riscv-none-embed-gcc/8.2.0/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: spi_com.c:(.text.spi_init+0x46): undefined reference to `PinMap_SPI_SSEL'
c:/users/nahusha k l/appdata/local/arduino15/packages/wch/tools/riscv-none-embed-gcc/8.2.0/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: spi_com.c:(.text.spi_init+0x4a): undefined reference to `PinMap_SPI_SSEL'
c:/users/nahusha k l/appdata/local/arduino15/packages/wch/tools/riscv-none-embed-gcc/8.2.0/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: spi_com.c:(.text.spi_init+0x54): undefined reference to `PinMap_SPI_MOSI'
c:/users/nahusha k l/appdata/local/arduino15/packages/wch/tools/riscv-none-embed-gcc/8.2.0/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: spi_com.c:(.text.spi_init+0x58): undefined reference to `PinMap_SPI_MISO'
c:/users/nahusha k l/appdata/local/arduino15/packages/wch/tools/riscv-none-embed-gcc/8.2.0/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: spi_com.c:(.text.spi_init+0x5c): undefined reference to `PinMap_SPI_SCLK'
c:/users/nahusha k l/appdata/local/arduino15/packages/wch/tools/riscv-none-embed-gcc/8.2.0/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: spi_com.c:(.text.spi_init+0x60): undefined reference to `PinMap_SPI_SSEL'
c:/users/nahusha k l/appdata/local/arduino15/packages/wch/tools/riscv-none-embed-gcc/8.2.0/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: spi_com.c:(.text.spi_init+0x120): undefined reference to `PinMap_SPI_MOSI'
c:/users/nahusha k l/appdata/local/arduino15/packages/wch/tools/riscv-none-embed-gcc/8.2.0/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: spi_com.c:(.text.spi_init+0x12c): undefined reference to `PinMap_SPI_MISO'
c:/users/nahusha k l/appdata/local/arduino15/packages/wch/tools/riscv-none-embed-gcc/8.2.0/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: spi_com.c:(.text.spi_init+0x138): undefined reference to `PinMap_SPI_SCLK'
c:/users/nahusha k l/appdata/local/arduino15/packages/wch/tools/riscv-none-embed-gcc/8.2.0/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: spi_com.c:(.text.spi_init+0x144): undefined reference to `PinMap_SPI_SSEL'
collect2.exe: error: ld returned 1 exit status

exit status 1

Compilation error: exit status 1

then i got this error, i wanted help to interface nrf24l01 PA LNA module with either arduino IDE or platform.io in vscode

yathAg commented 3 months ago

Have you used SPI for any other project?

If the spi library was written for Atmel boards you cannot use it with CH32 boards.

Further suggestion would be to open spi_com.c and see where the definitions are being called.

Nahusha-Karnam commented 3 months ago

https://github.com/openwch/arduino_core_ch32/blob/main/libraries/SPI/examples/SPIFlash/SPIFlash.ino can you look into this, does this code need to be flashed before or anything?