Hi All,
I asked chatgpt with my idea to solve it on a generic way
See the arduino code (as said code from chatgpt so i did not compile)
determine the lpf can be easily replaced by writing the right output pin.
Hope this helps to make the idea clear.
73 Johan
PA3GSB
raspberry pi (firmware)
if (i2c_filters_board) {
if (i2c_data != i2c_alex_data) {
i2c_data = i2c_alex_data;
unsigned char ldata[3];
ldata[0] = 0x02;
ldata[1] = ((i2c_alex_data >> 8) & 0xFF);
ldata[2] = (i2c_alex_data & 0xFF);
if (write(fd_i2c_filter, ldata, 3) < 0)
fprintf(stderr, "Error %d writing Alex data\n", errno);
fprintf(stderr, "Set Alex data 0 = %x \n", ldata[0]);
fprintf(stderr, "Set Alex data 1 = %x \n", ldata[1]);
fprintf(stderr, "Set Alex data 2 = %x \n", ldata[2]);
}
}
//*************************************************
// Send Mox Status
//*************************************************
if (i2c_filters_board & ((buffer[11] & 0x01) == 0x01 || (buffer[11] & 0x01) == 0x00)) {
currentMox = ((buffer[11] & 0x01) == 0x01) ? 1 : 0;
currentCW = cw;
if (currentMox != previousMox || currentCW != previousCW) {
previousMox = currentMox;
previousCW = currentCW;
unsigned char ldata[3];
ldata[0] = 0x03;
ldata[1] = ((buffer[11] & 0x01) == 0x01) ? 1 : 0;
ldata[2] = currentCW;
if (write(fd_i2c_filter, ldata, 3) < 0)
fprintf(stderr, "Error %d writing Alex data\n", errno);
fprintf(stderr, "PTT data 0 = %x \n", ldata[0]);
fprintf(stderr, "PTT data 1 = %x \n", ldata[1]);
fprintf(stderr, "PTT data 2 = %x \n", ldata[2]);
}
}
//*************************************************
// Send Frenquency to filter companion
//*************************************************
if (i2c_filters_board & (buffer[523] & 0xFE) == 0x12) {
if (currentfreq != previousfreq) {
previousfreq = currentfreq;
unsigned tempFreq = currentfreq;
unsigned char ldata[9];
ldata[0] = 0x04;
ldata[1] = (tempFreq / 10000000U) % 10;
ldata[2] = (tempFreq / 1000000U) % 10;
ldata[3] = (tempFreq / 100000U) % 10;
ldata[4] = (tempFreq / 10000U) % 10;
ldata[5] = (tempFreq / 1000U) % 10;
ldata[6] = (tempFreq / 100U) % 10;
ldata[7] = (tempFreq / 10U) % 10;
ldata[8] = (tempFreq / 1U) % 10;
if (write(fd_i2c_filter, ldata, 9) < 0)
fprintf(stderr, "Error %d setting frequency \n", errno);
else
fprintf(stderr, "Set Filters frequency to = %d \n", currentfreq);
}
}
}
Arduino code:
#include <Wire.h>
const int I2C_SLAVE_ADDRESS = 0x22; // Het I2C-adres van de Arduino
unsigned long currentfreq = 0;
unsigned long previousfreq = 0;
void setup() {
Wire.begin(I2C_SLAVE_ADDRESS); // Initialiseer I2C als slave
Wire.onReceive(receiveEvent); // Registreer de handler voor ontvangen data
Serial.begin(9600); // Start seriële communicatie voor debugging
}
void loop() {
// De loop blijft leeg, alles wordt afgehandeld in receiveEvent()
delay(100);
}
// Functie om data te ontvangen van Raspberry Pi
void receiveEvent(int numBytes) {
if (numBytes > 0) {
unsigned char receivedData[numBytes];
// Lees alle ontvangen bytes van I2C
for (int i = 0; i < numBytes; i++) {
receivedData[i] = Wire.read();
}
// Check wat voor commando we ontvangen hebben
switch (receivedData[0]) {
case 0x02: // Voor commando 0x02 (3 bytes totaal)
case 0x03: // Voor commando 0x03 (3 bytes totaal)
if (numBytes == 3) {
handleOtherCommands(receivedData);
}
break;
case 0x04: // Voor commando 0x04 (9 bytes totaal)
if (numBytes == 9) {
// Herbouw de frequentie uit de ontvangen cijfers
unsigned long tempFreq = (receivedData[1] * 10000000UL) +
(receivedData[2] * 1000000UL) +
(receivedData[3] * 100000UL) +
(receivedData[4] * 10000UL) +
(receivedData[5] * 1000UL) +
(receivedData[6] * 100UL) +
(receivedData[7] * 10UL) +
(receivedData[8] * 1UL);
// Update de huidige frequentie als deze anders is dan de vorige
if (tempFreq != previousfreq) {
previousfreq = tempFreq;
// Debugging: print de ontvangen frequentie
Serial.print("Ontvangen Frequentie: ");
Serial.println(tempFreq);
// Vertaal de frequentie naar LPF-waarde en toon op de seriële monitor
handleLPFFilters(tempFreq);
}
}
break;
default:
// Onbekend commando of fout
Serial.println("Onbekend commando ontvangen");
break;
}
}
}
// Functie om frequentie naar LPF-waarde te vertalen
void handleLPFFilters(unsigned long frequency) {
unsigned char lpf = 0;
// Bepaal de juiste LPF-waarde op basis van frequentie
if (frequency > 32000000) lpf = 0x10; /* bypass */
else if (frequency > 22000000) lpf = 0x20; /* 12/10 meters */
else if (frequency > 15000000) lpf = 0x40; /* 17/15 meters */
else if (frequency > 8000000) lpf = 0x01; /* 30/20 meters */
else if (frequency > 4500000) lpf = 0x02; /* 60/40 meters */
else if (frequency > 2400000) lpf = 0x04; /* 80 meters */
else lpf = 0x08; /* 160 meters */
// Debugging: print de LPF-waarde
Serial.print("LPF Waarde: 0x");
Serial.println(lpf, HEX);
}
// Functie voor het verwerken van andere commando's (0x02 en 0x03)
void handleOtherCommands(unsigned char receivedData[3]) {
// We kunnen hier de logica voor de commando's 0x02 en 0x03 implementeren.
// Omdat je zei dat deze genegeerd kunnen worden, kun je hier eventueel iets anders toevoegen als je wilt.
// Debugging: print het ontvangen commando en de 2 extra bytes
Serial.print("Commando ontvangen: 0x");
Serial.println(receivedData[0], HEX);
Serial.print("Data byte 1: 0x");
Serial.println(receivedData[1], HEX);
Serial.print("Data byte 2: 0x");
Serial.println(receivedData[2], HEX);
}
Op vrijdag 6 september 2024 om 07:43:04 UTC+2 schreef Yado-san:
Hi Wim,
I wondered why Ardiono's code was like this.
This is probably the code for the Generic Filter Switching Board. (when I2C=0x22, or Alex board).
If so, the relationship between frequency and code from the RB2 firmware should be as shown in the table below.
If the firmware is modified, it should be possible to separate 10m and 12m. (e.g FILTER_12m = 432;)
Yado-san, jg1twp
2024年8月20日火曜日 0:15:25 UTC+9 Wim PE1PWR: