Firmware one direction serial data transmission
Posted: Thu Oct 22, 2015 9:43 am
Hello,
I am developing a project where I want to send back from the model the serial NMEA data from a 10Hz gps. I got two OpenLRS v2 receivers and have modified the 1.12 firmware version code to try to do the work I pretend.
I want just one direction transmission, no hopping, and only serial data.
I can program the boards with no problem, but seems something is not working properly as I do not get anything at the receiver end.
Would you please take a look at the code I am dealing with and suggest changes?
Thanks a lot
#include <Arduino.h>
#include "config.h"
#include "functions.h"
#include "rfm22b.h"
void setup() {
//LEDs
pinMode(GREEN_LED_pin, OUTPUT);
pinMode(RED_LED_pin, OUTPUT);
//RF module pins
pinMode(SDO_pin, INPUT); //SDO
pinMode(SDI_pin, OUTPUT); //SDI
pinMode(SCLK_pin, OUTPUT); //SCLK
pinMode(IRQ_pin, INPUT); //IRQ
pinMode(nSel_pin, OUTPUT); //nSEL
pinMode(0, INPUT); // Serial Rx
pinMode(1, OUTPUT);// Serial Tx
pinMode(RSSI_OUT, OUTPUT); //RSSI pinout
Serial.begin(SERIAL_BAUD_RATE); //Serial Transmission
#if (COMPILATION_TX == 0)
attachInterrupt(IRQ_interrupt, RFM22B_Int, FALLING);
#endif
}
//############ MAIN LOOP ##############
void loop() {
unsigned char i, tx_data_length;
unsigned char first_data = 0;
Red_LED_ON;
RF22B_init_parameter(); // Configure the RFM22B's registers
frequency_configurator(CARRIER_FREQUENCY); // Calibrate the RFM22B to this frequency, frequency hopping starts from here.
to_rx_mode();
sei();
//Hop to first frequency from Carrier
Hopping();
delay(1000);
Red_LED_OFF;
Green_LED_ON;
delay(1000);
Green_LED_OFF;
#if (COMPILATION_TX == 1)
Red_LED_ON;
delay(1000);
Red_LED_OFF;
#endif
RF_Mode = Receive;
while (1) { /* MAIN LOOP */
if (_spi_read(0x0C) == 0) {
Red_LED_ON;
RF22B_init_parameter(); // detect the locked module and reboot
to_rx_mode();
}
#if (COMPILATION_TX == 0)
if (RF_Mode == Received) // RFM22B INT pin Enabled by received Data
{
Red_LED_OFF;
Green_LED_ON;
send_read_address(0x7f); // Send the package read command
for (i = 0; i < RF_PACK_SIZE; i++) //read all buffer
{
RF_Rx_Buffer = read_8bit_data();
}
rx_reset();
if (RF_Rx_Buffer[0] == 'B') // Brige values
{
for (i = 2; i < RF_Rx_Buffer[1] + 2; i++) //write serial
Serial.print(RF_Rx_Buffer);
}
Rx_RSSI = _spi_read(0x26); // Read the RSSI value
//***************************************
//* thUndead's RSSI MOD
//* info: RSSI voltage according to avg rssi value
rssicounter++; //counter which resets after getting to 41
if (rssicounter <= 40) rssipwm = rssipwm + Rx_RSSI ; //adds values into temp buffer
else rssicounter = 0;
if (rssicounter == 40)
{
rssipwm = rssipwm / 40; // averege 40 rssi values to get stable reading
rssibuf = map(rssipwm, 40, 120, 10, 250); //map value for pwm: MAX = 2.6v bad rssi unver 1 v
analogWrite(RSSI_OUT, rssibuf); //write the RSSI voltage
rssipwm = 0;
}
RF_Mode = Receive;
Green_LED_OFF;
}
#endif
#if (COMPILATION_TX == 1)
//######## TELEMETRY TRANSPARENT BRIDGE #########
byte total_rx_byte = Serial.available(); // Read the Serial RX buffer size
if (total_rx_byte > 0)
{
Red_LED_OFF;
Green_LED_ON;
if (total_rx_byte > RF_PACK_SIZE-2) total_rx_byte = RF_PACK_SIZE-2; // Limit the package size as 15 byte
RF_Tx_Buffer[0] = 'B'; // Brige command
RF_Tx_Buffer[1] = total_rx_byte;
for (byte i = 0; i < total_rx_byte; i++)
RF_Tx_Buffer[2 + i] = Serial.read();
to_tx_mode();
rx_reset();
Green_LED_OFF;
}
#endif
}
}
I am developing a project where I want to send back from the model the serial NMEA data from a 10Hz gps. I got two OpenLRS v2 receivers and have modified the 1.12 firmware version code to try to do the work I pretend.
I want just one direction transmission, no hopping, and only serial data.
I can program the boards with no problem, but seems something is not working properly as I do not get anything at the receiver end.
Would you please take a look at the code I am dealing with and suggest changes?
Thanks a lot
#include <Arduino.h>
#include "config.h"
#include "functions.h"
#include "rfm22b.h"
void setup() {
//LEDs
pinMode(GREEN_LED_pin, OUTPUT);
pinMode(RED_LED_pin, OUTPUT);
//RF module pins
pinMode(SDO_pin, INPUT); //SDO
pinMode(SDI_pin, OUTPUT); //SDI
pinMode(SCLK_pin, OUTPUT); //SCLK
pinMode(IRQ_pin, INPUT); //IRQ
pinMode(nSel_pin, OUTPUT); //nSEL
pinMode(0, INPUT); // Serial Rx
pinMode(1, OUTPUT);// Serial Tx
pinMode(RSSI_OUT, OUTPUT); //RSSI pinout
Serial.begin(SERIAL_BAUD_RATE); //Serial Transmission
#if (COMPILATION_TX == 0)
attachInterrupt(IRQ_interrupt, RFM22B_Int, FALLING);
#endif
}
//############ MAIN LOOP ##############
void loop() {
unsigned char i, tx_data_length;
unsigned char first_data = 0;
Red_LED_ON;
RF22B_init_parameter(); // Configure the RFM22B's registers
frequency_configurator(CARRIER_FREQUENCY); // Calibrate the RFM22B to this frequency, frequency hopping starts from here.
to_rx_mode();
sei();
//Hop to first frequency from Carrier
Hopping();
delay(1000);
Red_LED_OFF;
Green_LED_ON;
delay(1000);
Green_LED_OFF;
#if (COMPILATION_TX == 1)
Red_LED_ON;
delay(1000);
Red_LED_OFF;
#endif
RF_Mode = Receive;
while (1) { /* MAIN LOOP */
if (_spi_read(0x0C) == 0) {
Red_LED_ON;
RF22B_init_parameter(); // detect the locked module and reboot
to_rx_mode();
}
#if (COMPILATION_TX == 0)
if (RF_Mode == Received) // RFM22B INT pin Enabled by received Data
{
Red_LED_OFF;
Green_LED_ON;
send_read_address(0x7f); // Send the package read command
for (i = 0; i < RF_PACK_SIZE; i++) //read all buffer
{
RF_Rx_Buffer = read_8bit_data();
}
rx_reset();
if (RF_Rx_Buffer[0] == 'B') // Brige values
{
for (i = 2; i < RF_Rx_Buffer[1] + 2; i++) //write serial
Serial.print(RF_Rx_Buffer);
}
Rx_RSSI = _spi_read(0x26); // Read the RSSI value
//***************************************
//* thUndead's RSSI MOD
//* info: RSSI voltage according to avg rssi value
rssicounter++; //counter which resets after getting to 41
if (rssicounter <= 40) rssipwm = rssipwm + Rx_RSSI ; //adds values into temp buffer
else rssicounter = 0;
if (rssicounter == 40)
{
rssipwm = rssipwm / 40; // averege 40 rssi values to get stable reading
rssibuf = map(rssipwm, 40, 120, 10, 250); //map value for pwm: MAX = 2.6v bad rssi unver 1 v
analogWrite(RSSI_OUT, rssibuf); //write the RSSI voltage
rssipwm = 0;
}
RF_Mode = Receive;
Green_LED_OFF;
}
#endif
#if (COMPILATION_TX == 1)
//######## TELEMETRY TRANSPARENT BRIDGE #########
byte total_rx_byte = Serial.available(); // Read the Serial RX buffer size
if (total_rx_byte > 0)
{
Red_LED_OFF;
Green_LED_ON;
if (total_rx_byte > RF_PACK_SIZE-2) total_rx_byte = RF_PACK_SIZE-2; // Limit the package size as 15 byte
RF_Tx_Buffer[0] = 'B'; // Brige command
RF_Tx_Buffer[1] = total_rx_byte;
for (byte i = 0; i < total_rx_byte; i++)
RF_Tx_Buffer[2 + i] = Serial.read();
to_tx_mode();
rx_reset();
Green_LED_OFF;
}
#endif
}
}