I am currently working on a project where I use an Arduino Nano to decode and encode CTCSS codes.
I want to set the CTCSS code selected by the transceiver, an Icom IC275H. Serial data, clock and latch, are available for this. I created the code below that reads the sent data.
int readShiftRegister() {
SPCR = (1<<SPE)|(0<<DORD)|(0<<MSTR)|(1<<CPOL)|(1<<CPHA)|(1<<SPR1)|(1<<SPR0); // SPI on
while(!(SPSR & (1<<SPIF))) ; // SPIF bit set when 8 bits received
shiftRegister = SPDR;
SPCR = (0<<SPE)|(0<<DORD)|(0<<MSTR)|(1<<CPOL)|(1<<CPHA)|(1<<SPR1)|(1<<SPR0); // SPI off
while (digitalRead(SS)==0) {} // wait until SlaveSelect goes low (active)
int code = 0;
if (shiftRegister >= 0) {
for (int i =0; i < numCodes; i++) {
if (shiftRegister == ctcssCodes[i]) {
code = i;
Serial.print("Code: ");
Serial.println(shiftRegister, DEC);
break;
}
}
}
return code; // Returns the code send by transceiver
}
Pins used:
PIN 2 = PTT_BUTTON to switch from receive to transmit
PIN 3 = PWM_OUTPUT output that generates the sub-audio tone
PIN 8 = DECODE_INDICATOR goes high if CTCSS code is decoded
PIN 10 = latchPin Input of the latch from the transceiver
PIN 11 = MOSI SPI data from transceiver
PIN 13 = SCK SPI clock serial clock from transceiver
PIN 14 = A0 Sub-audio tone input, needs 260Hz lowpass filter
On the scope the signals look like this:
Yellow = Data
Purple = Clock
Blue = Latch.
The data decoded as 154 corresponds to the 77Hz sub audio setting
The problem is that not all data is read by the program, probably because the latch is only high for 4.2usec and is not compatible with the SPI protocol. So if I select a CTCSS code on the transceiver, it skips settings.
I have already tried many versions of the code but have not yet found a stable way. So it could use some help. The full program can be found at GitHub - PA2ER/Icom-CTCSS
Info on CTCSS can be found at Continuous Tone-Coded Squelch System - Wikipedia. But that is not the protocol used bij the transceiver to communicate with the arduino nano, that is managed by a serial 8 bit data.
No it is not the rs232 cat connection of the transceiver. The transceiver has a option for a CTCSS encoder inside. The schematic of the factory CTCSS module is this.
I use the data, ck, and the tsto on connector J2. As you can see it uses a 8bit shiftregister, to translate the serial data to parallel. I try to read the serial data from the transceiver with the arduino nano, to generate the tone that is sellected on the transceiver.
I have already done that and works fine. But as you can see from the scope image, the latch signal goes high after the data is sent, which does not match the SPI specifications. It would be nice to read the data in a different way than with the spi function. but I'm afraid I would have to use 2 interrupts for this. Namely for the clock and for the latch.
Ignore the Latch , just read the Data after every Clock ,( Bit bang).
Play around with the timing after the Clock is detected High or Low , Data transition on High or Low?
If I ignore the latch, I do get all the data. But also the other data that goes over the serial bus, and is therefore not relevant. So the latch pin functions as a chip select.
Why are you doing this? If the CTCSS board is in the IC275H then the rig is able to encode and decode. I don't see what additional functionality you are trying to provide with the NANO.
Does the rig have the ability to set and read CTCSS using the CI-V protocol? It would be a lot easier to play with if it does.
Ohhh. So you are "hacking" into the rig to get the NANO to function in place of the CTCSS board and you need to reverse engineer the internal protocol of the CTCSS board. Hmmmm. That'll be fun!
Sure is. I have it working, but the only problem i stil have, is that the arduino does not follow the chip-select. So I get all of the data from the serial bus, not only the 8bit data for the CTCSS frequentie.
Thanks for pointing me out. Just discover that i have spikes of 1 volt pp on the chip-select output, when I turn the VFO dial on the transceiver. Maybe that is causing the problems.