光学エンコーダは、中華製400P/R($10位)を使ったため、エンコーダのコントロールSTEPは、1Hz、10Hz、100Hzにした。
スケッチ
JA2NKD OMのオリジナルVFOは、max 8 Bandであるが6 Bandに変更している。VFO周波数は、周波数変化が2秒以上なければ、疑似EEPROMに保存する機能を追加した。si5351a2.hは、オリジナルの物を使っている。ただ、Ucglib.hは私のPC環境で複数のライブラリが参照されるため、参照場所の明確化をした。スケッチと関係ファイルは、download siteのstm32フォルダからダウンロード可能。///////////////////////////////////////////////////////////////////////////////////
// stm32 + si5351a VFO(With BFO) Ver1.01
// (Based on 'JAN2KD 2016.10.19 Multi Band DDS VFO Ver3.1')
//
// 2017/9/16
// JA2GQP
///////////////////////////////////////////////////////////////////////////////////
//---------- Library include ----------
#include "si5351a2.h"
#include <SPI.h>
#include <EEPROM.h>
#include <Rotary.h>
#include "src/Ucglib.h"
//---------- Encorder setting ---------------
#define ENC_A PB12 // Rotary encoder A
#define ENC_B PB13 // Rotary encoder B
Rotary r=Rotary(ENC_A,ENC_B);
//---------- TFT setting -------------------
#define __CS PB10 // CS
#define __DC PB0 // D/C
#define __RST PB1 // RESET
Ucglib_ILI9341_18x240x320_HWSPI ucg(__DC, __CS, __RST);
//---------- CW Tone -------------------
#define CW_TONE 700 // 700Hz
//---------- I/O Assign -------------------
#define MODE_OUT1 PB15 // 2017/9/17
#define MODE_OUT2 PA8 // 2017/9/17
#define BAND_OUT1 PB3
#define BAND_OUT2 PB4
#define BAND_OUT3 PB5
#define SW_BAND PA0
#define SW_MODE PC14
#define SW_STEP PB14
#define SW_RIT PC15
#define SW_TX PC13
#define METER PA1
#define EEP_BAND 0x00 // EEPROM BAND Adress
#define EEP_INIT 0x0e // INIT end Adress
//---------- Variable setting ----------
long romf[4]; // EEPROM freq copy buffer
long freq = 7100000;
long freqmax = 7200000;
long freqmin = 7000000;
long freqold = 0;
long freqrit = 0;
String freqt=String(freq); // Frequency text
long ifshift = 0;
long ifshiftb;
long romb[5]; // EEPROM bfo copy buffer
long vfofreq = 0;
long vfofreqb;
char f100m,f10m,fmega,f100k,f10k,f1k,f100,f10,f1;
int rit = 0;
int fstep = 100;
uint16 steprom = 1;
uint16 fmode = 3;
uint16 fmodeb = 3;
int fmodeold = 1;
int flagrit = 0;
int fritold = 0;
int flagmode = 0;
int meterval1 = 0;
int tmeterval = 0;
int romadd = 0;
int rombadd = 0;
int analogdata = 0;
uint16 band = 0; // 3.5MHz
int bandmax = 6; // 6band
uint16 Status;
uint16 Data;
unsigned long eep_freq[4];
int eep_romadd;
int eep_fstep;
int eep_fmode;
unsigned long eep_bfo[6];
int eep_rombadd;
int_fast32_t timepassed; // int to hold the arduino miilis since startup
int flg_frqwt = 0; // Frequency data Wite Flag(EEPROM)
int flg_bfowt = 0; // BFO Wite Flag(EEPROM)
int flg_bfochg = 0; // BFO Wite Flag(EEPROM)
//---------- Initialization Program ----------------------
void setup() {
timepassed = millis();
afio_cfg_debug_ports(AFIO_DEBUG_NONE); // ST-LINK(PB3,PB4,PA15,PA12,PA11) Can be used
Wire.begin();
pinMode( ENC_A,INPUT_PULLUP); // PC13 pull up
pinMode( ENC_B,INPUT_PULLUP); // PC14
attachInterrupt( ENC_A, Rotaly_enc, CHANGE); // Encorder A
attachInterrupt( ENC_B, Rotaly_enc, CHANGE); // B
delay(100);
ucg.begin(UCG_FONT_MODE_TRANSPARENT);
ucg.clearScreen();
ucg.setRotate270();
pinMode(SW_BAND,INPUT_PULLUP);
pinMode(SW_MODE,INPUT_PULLUP);
pinMode(SW_STEP,INPUT_PULLUP);
pinMode(SW_RIT,INPUT_PULLUP);
pinMode(SW_TX,INPUT_PULLUP);
pinMode(ENC_A,INPUT_PULLUP); // pull up encorede A
pinMode(ENC_B,INPUT_PULLUP); // encorder B
pinMode (BAND_OUT1,OUTPUT);
pinMode (BAND_OUT2,OUTPUT);
pinMode (BAND_OUT3,OUTPUT);
pinMode(SW_TX,INPUT_PULLUP);
pinMode(MODE_OUT1,OUTPUT);
pinMode(MODE_OUT2,OUTPUT);
Fnc_eepINIT();
delay(100);
band2eep();
delay(100);
Status = EEPROM.read(EEP_BAND,&band); // EEPROM read(frequency)
romadd=0x010+(band*0x10);
for (int i=0; i<3;i++){
romf[i]=Fnc_eepRD((romadd+4*i));
}
freq = romf[0];
freqmin = romf[1];
freqmax = romf[2];
Status = EEPROM.read(romadd+12,&fmode);
Status = EEPROM.read(romadd+14,&steprom);
eep_rombadd=0x090; // EEPROM read(BFO)
for (int i=0; i<4;i++){
romb[i]=Fnc_eepRD((eep_rombadd+(4*i)));
eep_bfo[i] = romb[i];
}
if (steprom==1){fstep=1;} // STEP set
if (steprom==2){fstep=10;}
if (steprom==3){fstep=100;}
banddataout();
screen01();
chlcd();
modeset();
steplcd();
freqt=String(freq);
freqlcd();
}
//---------- Main program ---------------------------------
void loop() {
if(digitalRead(SW_STEP) == LOW) // STEP sw check
setstep();
else if(digitalRead(SW_MODE) == LOW) // MODE sw check
modesw();
else if(digitalRead(SW_RIT) == LOW) // RIT sw check
setrit();
else if(digitalRead(SW_BAND) == LOW) // BAND sw check
bandcall();
if (digitalRead(SW_TX)==LOW) // TX sw check
txset();
if (flagrit==1){
if (freqrit == fritold){
meter();
}
if (freqrit!=fritold){
PLL_write();
ritlcd();
fritold=freqrit;
}
}
else{
if (freq == freqold){
meter();
}
PLL_write();
freqt=String(freq);
freqlcd();
freqold=freq;
}
if((flg_frqwt == 1) && (flg_bfochg == 0)){ // EEPROM auto save 2sec
if(timepassed+1000 < millis()){
bandwrite();
flg_frqwt = 0;
}
}
}
//---------- EEPROM Data initialization ---------------
void band2eep(){
Status = EEPROM.read(EEP_INIT,&Data);
if(Data != 73){ // Iinitialization check
Status = EEPROM.write(EEP_BAND,1);
eep_romadd=0x010; // BAND:0 ROMadd:0x010
eep_freq[0]=3500000;
eep_freq[1]=3500000;
eep_freq[2]=3800000;
eep_fmode=0;
eep_fstep=2;
band2write();
eep_romadd=0x020; // BAND:1 ROMadd:0x020
eep_freq[0]=7000000;
eep_freq[1]=7000000;
eep_freq[2]=7200000;
eep_fmode=0;
eep_fstep=2;
band2write();
eep_romadd=0x030; // BAND:2 ROMadd:0x030
eep_freq[0]=10100000;
eep_freq[1]=10100000;
eep_freq[2]=10150000;
eep_fmode=2;
eep_fstep=1;
band2write();
eep_romadd=0x040; // BAND:3 ROMadd:0x040
eep_freq[0]=14000000;
eep_freq[1]=14000000;
eep_freq[2]=14350000;
eep_fmode=1;
eep_fstep=2;
band2write();
eep_romadd=0x050; // BAND:4 ROMadd:0x050
eep_freq[0]=21000000;
eep_freq[1]=21000000;
eep_freq[2]=21450000;
eep_fmode=1;
eep_fstep=2;
band2write();
eep_romadd=0x060; // BAND:5 ROMadd:0x060
eep_freq[0]=28000000;
eep_freq[1]=28000000;
eep_freq[2]=29700000;
eep_fmode=1;
eep_fstep=2;
band2write();
eep_rombadd=0x090; // BFO ROMadd:0x090
eep_bfo[0]=7999600; // LSB
eep_bfo[1]=8002600; // USB
eep_bfo[2]=8000400; // CW
eep_bfo[3]=8001100; // AM
for (int i=0;i<4;i++){
Fnc_eepWT(eep_bfo[i],(eep_rombadd+4*i));
}
Status = EEPROM.write(EEP_INIT,73); // Initialyzed End code
}
}
//---------- Function Band Write to EEPROM ---------------
void band2write(){
for (int i=0;i<3;i++){
Fnc_eepWT(eep_freq[i],(eep_romadd+4*i));
}
Status = EEPROM.write(eep_romadd+12,eep_fmode);
Status = EEPROM.write(eep_romadd+14,eep_fstep);
}
//---------- PLL write ---------------------------
void PLL_write(){
if(flg_bfochg == 0){
if (flagrit==0)
vfofreq=freq+ifshift;
else
vfofreq=freq+ifshift+freqrit;
Vfo_out(vfofreq); // DDS out 2016/10/24 JA2GQP
Bfo_out(ifshift); // BFO
}
else{
ifshift = freq;
Bfo_out(ifshift); // BFO
freq = ifshift;
}
}
//---------- VFO out ---------------
void Vfo_out(long frequency){
if(vfofreq != vfofreqb){
si5351aSetFrequency(frequency);
flg_frqwt = 1; // EEP Wite Flag
timepassed = millis();
vfofreqb = vfofreq;
}
}
//---------- BFO out ---------------
void Bfo_out(long frequency){
if(ifshift != ifshiftb){
si5351aSetFrequency2(frequency);
flg_bfowt = 1; // EEP Wite Flag
ifshiftb = ifshift;
}
}
//---------- meter --------------------------
void meter(){
meterval1=analogRead(METER);
// meterval1=meterval1/50; // old
meterval1=meterval1/200;
if (meterval1>15){meterval1=15;}
int sx1=sx1+(meterval1*17);
sx1=sx1+41;
int sx2=0;
sx2=sx2+(40+((15-meterval1)*17));
ucg.setFont(ucg_font_fub35_tr);
ucg.setColor(0,0,0);
ucg.drawBox(sx1,180,sx2,16);
ucg.setPrintPos(40,200);
for(int i=1;i<=meterval1;i++){
if (i<=9){
ucg.setColor(0,255,255);
ucg.print("-");
}
else{
ucg.setColor(255,0,0);
ucg.print("-");
}
}
}
//---------- Encoder Interrupt -----------------------
void Rotaly_enc(){
if (flagrit==1){
unsigned char result = r.process();
if(result) {
if(result == DIR_CW){
freqrit=freqrit+fstep;
if (freqrit>=10000){
freqrit=10000;
}
}
else{
freqrit=freqrit-fstep;
if (freqrit<=-10000){
freqrit=-10000;
}
}
}
}
else{
unsigned char result = r.process();
if(result) {
if(result == DIR_CW){
freq=freq+fstep;
if((flg_bfochg == 0) && (freq>=freqmax)){freq=freqmax;}
}
else{
freq=freq-fstep;
if((flg_bfochg == 0) && (freq<=freqmin)){freq=freqmin;}
}
}
}
}
//------------ On Air -----------------------------
void txset(){
if(fmode == 2) // CW?
Vfo_out(vfofreq + CW_TONE); // Vfofreq+700Hz
else
Vfo_out(vfofreq); // vfo out
ucg.setPrintPos(110,140);
ucg.setFont(ucg_font_fub17_tr);
ucg.setColor(255,0,0);
ucg.print("ON AIR");
while(digitalRead(SW_TX) == LOW){
meter();
}
ucg.setFont(ucg_font_fub17_tr);
ucg.setColor(0,0,0);
ucg.drawBox(100,120,250,30); //45
}
//------------- Mode set(LSB-USB-CW-AM) ------------
void modeset(){
ucg.setFont(ucg_font_fub17_tr);
ucg.setPrintPos(82,82);
ucg.setColor(0,0,0);
ucg.print("USB");
ucg.setPrintPos(12,82);
ucg.print("LSB");
ucg.setPrintPos(82,112);
ucg.print("A M");
ucg.setPrintPos(12,112);
ucg.print("C W");
switch(fmode){
case 0: // LSB
ifshift = eep_bfo[0];
ucg.setPrintPos(12,82);
ucg.setColor(255,255,0);
ucg.print("LSB");
digitalWrite(MODE_OUT1,LOW);
digitalWrite(MODE_OUT2,LOW);
break;
case 1: // USB
ifshift = eep_bfo[1];
ucg.setColor(255,255,0);
ucg.setPrintPos(82,82);
ucg.print("USB");
digitalWrite(MODE_OUT1,HIGH);
digitalWrite(MODE_OUT2,LOW);
break;
case 2: // CW
ifshift = eep_bfo[2];
ucg.setPrintPos(12,112);
ucg.setColor(255,255,0);
ucg.print("C W");
digitalWrite(MODE_OUT1,LOW);
digitalWrite(MODE_OUT2,HIGH);
break;
case 3: // AM
ifshift = eep_bfo[3];
ucg.setPrintPos(82,112);
ucg.setColor(255,255,0);
ucg.print("A M");
digitalWrite(MODE_OUT1,HIGH);
digitalWrite(MODE_OUT2,HIGH);
break;
default:
ifshift = eep_bfo[0];
ucg.setPrintPos(12,82);
ucg.setColor(255,255,0);
ucg.print("LSB");
digitalWrite(MODE_OUT1,LOW);
digitalWrite(MODE_OUT2,LOW);
fmode = 0;
break;
}
}
//------------- Mode set SW ------------
void modesw(){
int cnt = 0;
if(flg_bfochg == 0){
while(digitalRead(SW_MODE) == LOW){
delay(100);
cnt++;
if(10 <= cnt){ // BFO data change mode(1sec)
romadd=0x010+(band*0x10);
romf[0]=Fnc_eepRD(romadd);
freq = Fnc_eepRD(0x090+(fmode * 4));
freqt=String(freq);
freqlcd();
ucg.setPrintPos(110,140);
ucg.setFont(ucg_font_fub17_tr);
ucg.setColor(255,255,0);
ucg.print("BFO ADJ");
fmodeb = fmode;
flg_bfochg = 1;
break;
}
}
}
else{
while(digitalRead(SW_MODE) == LOW){
delay(100);
cnt++;
if(10 <= cnt){ // BFO data update(1sec)
ifshift = freq;
Fnc_eepWT(ifshift,0x090+(fmode * 4)); // data write
eep_bfo[fmode] = ifshift;
freq = romf[0];
freqt=String(freq);
freqlcd();
ucg.setFont(ucg_font_fub17_tr);
ucg.setColor(0,0,0);
ucg.drawBox(100,120,250,30); //45
flg_bfochg = 0;
fmode--;
break;
}
}
}
if(flg_bfochg == 0)
fmode++;
modeset();
PLL_write();
while(digitalRead(SW_MODE) == LOW);
}
//------------ Rit SET ------------------------------
void setrit(){
if(flagrit==0){
flagrit=1;
ucg.setFont(ucg_font_fub11_tr);
ucg.setPrintPos(190,110);
ucg.setColor(255,0,0);
ucg.print("RIT");
ritlcd();
}
else {
flagrit=0;
vfofreq=freq+ifshift;
Vfo_out(vfofreq); // DDS Out 2016/10/23 JA2GQP
freqt=String(freq);
ucg.setFont(ucg_font_fub11_tr);
ucg.setPrintPos(190,110);
ucg.setColor(255,255,255);
ucg.print("RIT");
ucg.setColor(0,0,0);
ucg.drawRBox(222,92,91,21,3);
freqrit=0;
}
while(digitalRead(SW_RIT) == LOW);
}
//----------- Rit screen ----------------------
void ritlcd(){
ucg.setColor(0,0,0);
ucg.drawBox(222,92,91,21);
ucg.setFont(ucg_font_fub17_tr);
ucg.setColor(255,255,255);
ucg.setPrintPos(230,110);
ucg.print(freqrit);
}
//-------------- encorder frequency step set -----------
void setstep(){
if (fstep==100){
fstep=1;
}
else{
fstep=fstep * 10;
}
steplcd();
while(digitalRead(SW_STEP) == LOW);
}
//------------- Step Screen ---------------------------
void steplcd(){
ucg.setColor(0,0,0);
ucg.drawRBox(221,61,93,23,3);
ucg.setFont(ucg_font_fub17_tr);
ucg.setColor(255,255,255);
ucg.setPrintPos(220,80);
if (fstep==1){ucg.print(" 1Hz");}
if (fstep==10){ucg.print(" 10Hz");}
if (fstep==100){ucg.print(" 100Hz");}
}
//----------- Main frequency screen -------------------
void freqlcd(){
ucg.setFont(ucg_font_fub35_tn);
int mojisuu=(freqt.length());
if(freq<100){
ucg.setColor(0,0,0);
ucg.drawBox(217,9,28,36);
}
if(f10 !=(freqt.charAt(mojisuu-2))){
ucg.setColor(0,0,0);
ucg.drawBox(245,9,28,36);
ucg.setPrintPos(245,45);
ucg.setColor(0,255,0);
ucg.print(freqt.charAt(mojisuu-2));
f10 = (freqt.charAt(mojisuu-2));
}
if(freq<10){
ucg.setColor(0,0,0);
ucg.drawBox(245,9,28,36);
}
if(f1 !=(freqt.charAt(mojisuu-1))){
ucg.setColor(0,0,0);
ucg.drawBox(273,9,28,36);
ucg.setPrintPos(273,45);
ucg.setColor(0,255,0);
ucg.print(freqt.charAt(mojisuu-1));
f1 = (freqt.charAt(mojisuu-1));
}
if(freq<1000){
ucg.setColor(0,0,0);
ucg.drawBox(202,9,15,36);
}
if(f100 !=(freqt.charAt(mojisuu-3))){
ucg.setColor(0,0,0);
ucg.drawBox(217,9,28,36);
ucg.setPrintPos(217,45);
ucg.setColor(0,255,0);
ucg.print(freqt.charAt(mojisuu-3));
f100 = (freqt.charAt(mojisuu-3));
}
if(freq>=1000){
ucg.setPrintPos(202,45);
ucg.setColor(0,255,0);
ucg.print(".");
}
if(freq<10000){
ucg.setColor(0,0,0);
ucg.drawBox(146,9,28,36);
}
if(f1k !=(freqt.charAt(mojisuu-4))){
ucg.setColor(0,0,0);
ucg.drawBox(174,9,28,36);
ucg.setPrintPos(174,45);
ucg.setColor(0,255,0);
ucg.print(freqt.charAt(mojisuu-4));
f1k = (freqt.charAt(mojisuu-4));
}
if(freq<100000){
ucg.setColor(0,0,0);
ucg.drawBox(118,9,28,36);
}
if(f10k !=(freqt.charAt(mojisuu-5))){
ucg.setColor(0,0,0);
ucg.drawBox(146,9,28,36);
ucg.setPrintPos(146,45);
ucg.setColor(0,255,0);
ucg.print(freqt.charAt(mojisuu-5));
f10k = (freqt.charAt(mojisuu-5));
}
if(freq<1000000){
ucg.setColor(0,0,0);
ucg.drawBox(103,9,15,36);
}
if(f100k !=(freqt.charAt(mojisuu-6))){
ucg.setColor(0,0,0);
ucg.drawBox(118,9,28,36);
ucg.setPrintPos(118,45);
ucg.setColor(0,255,0);
ucg.print(freqt.charAt(mojisuu-6));
f100k = (freqt.charAt(mojisuu-6));
}
if(freq>=1000000){
ucg.setPrintPos(103,45);
ucg.setColor(0,255,0);
ucg.print(".");
}
if(freq<10000000){
ucg.setColor(0,0,0);
ucg.drawBox(47,9,28,36);
}
if(fmega !=(freqt.charAt(mojisuu-7))){
ucg.setColor(0,0,0);
ucg.drawBox(75,9,28,36);
ucg .setPrintPos(75,45);
ucg.setColor(0,255,0);
ucg.print(freqt.charAt(mojisuu-7));
fmega = (freqt.charAt(mojisuu-7));
}
if(freq<100000000){
ucg.setColor(0,0,0);
ucg.drawBox(19,9,28,36);
}
if (f10m !=(freqt.charAt(mojisuu-8))){
ucg.setColor(0,0,0);
ucg.drawBox(47,9,28,36);
ucg .setPrintPos(47,45);
ucg.setColor(0,255,0);
ucg.print(freqt.charAt(mojisuu-8));
f10m = (freqt.charAt(mojisuu-8));
}
}
//----------- Basic Screen -------------------------
void screen01(){
ucg.setColor(255,255,255);
ucg.drawRFrame(1,1,314,55,5);
ucg.drawRFrame(2,2,312,53,5);
ucg.setColor(50,50,50);
ucg.drawRBox(5,60,60,25,3);
ucg.drawRBox(75,60,60,25,3);
ucg.drawRBox(5,90,60,25,3);
ucg.drawRBox(75,90,60,25,3);
ucg.setFont(ucg_font_fub17_tr);
ucg.setPrintPos(12,82);
ucg.setColor(0,0,0);
ucg.print("LSB");
ucg.setPrintPos(82,82);
ucg.print("USB");
ucg.setPrintPos(12,112);
ucg.print("C W");
ucg.setPrintPos(82,112);
ucg.print("A M");
ucg.setColor(255,255,255);
ucg.drawRFrame(220,60,95,25,3);
ucg.drawRFrame(220,90,95,25,3);
ucg.setFont(ucg_font_fub11_tr);
ucg.setColor(255,255,255);
ucg.setPrintPos(175,80);
ucg.print("STEP");
ucg.setPrintPos(190,110);
ucg.setColor(255,255,255);
ucg.print("RIT");
ucg.setColor(100,100,100);
ucg.setPrintPos(10,210);
ucg.print(" S: 1-----3-------6-------9---Over--------");
ucg.setPrintPos(10,177);
ucg.print(" P: 1-----3-----5-----------10--------------");
ucg.setPrintPos(10,230);
ucg.setColor(235,0,200);
ucg.print( "stm32 VFO(with BFO) Ver1.0 JA2GQP");
ucg.setFont(ucg_font_fub35_tr);
ucg.setColor(0,255,0);
ucg.setPrintPos(273,45);
ucg.print("0");
}
//---------- Band data call from eeprom ----------
void bandcall(){
band=band+1;
if (band>(bandmax-1)){band=0;}
romadd=0x010+(band*0x010);
for (int i=0; i<3;i++){
romf[i]=Fnc_eepRD((romadd+4*i));
}
freq = romf[0];
freqmin = romf[1];
freqmax = romf[2];
Status = EEPROM.read(romadd+12,&fmode);
Status = EEPROM.read(romadd+14,&steprom);
if (steprom==1){fstep=1;}
if (steprom==2){fstep=10;}
if (steprom==3){fstep=100;}
modeset();
steplcd();
freqt=String(freq);
freqlcd();
banddataout();
chlcd();
while(digitalRead(SW_BAND) == LOW);
}
//---------- Band data write to eeprom ----------
void bandwrite(){
romadd=0x010+(band*0x010);
Fnc_eepWT(freq,romadd);
Status = EEPROM.write(EEP_BAND,band);
Status = EEPROM.write(romadd+12,fmode);
if (fstep==1){steprom=1;}
if (fstep==10){steprom=2;}
if (fstep==100){steprom=3;}
Status = EEPROM.write(romadd+14,steprom);
}
//---------- Function EEPROM Initialize ---------
void Fnc_eepINIT(){
uint16 dummy;
EEPROM.PageBase0 = 0x801F000;
EEPROM.PageBase1 = 0x801F800;
EEPROM.PageSize = 0x400; // 2kB
dummy = EEPROM.init();
}
//---------- Function EEPROM Read(4byte) ---------
long Fnc_eepRD(uint16 adr){
long val = 0;
uint16 dat,dummy;
dummy = EEPROM.read(adr,&dat);
val = dat << 16;
dummy = EEPROM.read(adr+1,&dat);
return val | dat;
}
//---------- Function EEPROM Write(4byte) ---------
void Fnc_eepWT(long dat,uint16 adr){
uint16 dummy,val;
val = dat & 0xffff;
dummy = EEPROM.write(adr+1,val);
val = dat >> 16;
val = val & 0xffff;
dummy = EEPROM.write(adr,val);
}
//---------- Band data output I/O ----------
void banddataout(){
digitalWrite(BAND_OUT1,LOW);
digitalWrite(BAND_OUT2,LOW);
digitalWrite(BAND_OUT3,LOW);
if (band==0){}
if (band==1){
digitalWrite( BAND_OUT1,HIGH);
}
if (band==2){
digitalWrite(BAND_OUT2,HIGH);
}
if (band==3){
digitalWrite(BAND_OUT1,HIGH);
digitalWrite(BAND_OUT2,HIGH);
}
if (band==4){
digitalWrite(BAND_OUT3,HIGH);
}
if (band==5){
digitalWrite(BAND_OUT1,HIGH);
digitalWrite(BAND_OUT3,HIGH);
}
if (band==6){
digitalWrite(BAND_OUT2,HIGH);
digitalWrite(BAND_OUT3,HIGH);
}
if (band==7){
digitalWrite(BAND_OUT1,HIGH);
digitalWrite(BAND_OUT2,HIGH);
digitalWrite(BAND_OUT3,HIGH);
}
}
//---------- Band No.(Chanel No.) write to LCD ----------
void chlcd(){
ucg.setColor(0,0,0);
ucg.drawBox(5,120,80,20);
ucg.setFont(ucg_font_fub11_tr);
ucg.setPrintPos(12,137);
ucg.setColor(255,255,255);
ucg.print("CH: ");
ucg.print(band+1);
}
92 件のコメント:
Hi JA2GQP I don´t speak Japanese, but I hope You could Understand English :P
I´m looking for a multifeature VFO which uses SI5351, a0,96 I2C oled and Aduino. There´s something on Internet, but no sketch, nothing. It comes with 18 menus, FCC Standard Channels, even more. Are You cb Vfo able to handle these options?
73 from Brazil :)
Hi emercito.
I think it is difficult to find a product that perfectly meets your specifications even if you search the web. I think some kind of modification is necessary.
There is a thing of specification close to the VFO introduced in my Blog.
1.
https://ja2gqp.blogspot.com/2019/04/si5351-oled-3band-vfo.html
This VFO is a simple 3-band thing that does not include BFO.
2.
https://ja2gqp.blogspot.com/2016/06/si5351-vfo.html
This is a multi-band product using nokia5110 for the display. This VFO is popular.
Both VFOs do not have peripheral control such as relay switching circuit control. Relay control can be achieved with a simple modification.
hello, is it possible to send me the sketch and the libraries of the version with BFO?
my e-mail: py2wy@hotmail.com
TNX
Hi Wander.
Public files are on my download site.
https://sites.google.com/site/ja2gqp/
Download stm32_si5351a.zip from the stm32 folder on this site.
I did not find the library #include "src / Ucglib.h"
Download the general ones used in Arduino IDE from Git Hub. I only supply customized ones.
If it is not included in the zip file, use the one that is generally available.
I understood about the library.
when I write from the following error message:
'PB12' was not declared in this scope
Public sketches should compile without error. This sketch is a stable software that many people use. PB12 is a port of stm32f103c8t6. The fact that this port is not recognized means that the development environment for stm32f103c8t6 is not ready. Arduino IDE may not have the development environment for stm32f103c8t6.
Got a BFO version for arduino nano atmega328?
My sketch is stm32 version and BFO compatible. Please read the public contents. It does not work with atmega328p. Atmega328p does not have enough memory so it is difficult to support BFO.
If you use atmega32p, it is here.
https://ja2gqp.blogspot.com/2017/06/si5351a-tft-vfo-ver11.html
Please read the contents carefully because various VFOs are available.
Now with smt32 correctly installed, when I load Sketch, error message:
exit status 1
'xtalFreq' was not declared in this scope
Hi Wander.
Save si5351a2.h in the same directory as the sketch. xtalfreq is declared in si5351a2.h. My site is intended for people who know the basics, so I don't know if I won't reply in the future.
everything is working perfectly, just no signal on clk0 and clk2 of SI5153, SDA PB7 and SCL PB6? What should I do, thanks for your patience.
hello ja2gqp
is TFT display 2,8inch 240x320 ok for this project ?
thanks in advance..73 de 9a3xz Mikele
Hi Mikele.
OK if SPI 240x320.
thanks so much !
how to handle ucglib.h erorr in the section not in the directory libmaple / dma.h
Hi AWR_Android_SRC.
This VFO was developed in the Arduino IDE environment. Not development with Maple. Therefore, Maple related items are not included. I can't reply to questions. A sketch of this VFO can be found in the stm32 folder on the download site.
https://sites.google.com/site/ja2gqp/
error description like this
C: \ Users \ AWR \ AppData \ Local \ Temp \ arduino_build_519055 \ sketch \ src / Ucglib.h: 56: 11: fatal error: libmaple / dma.h: No such file or directory
56 | #include
| ^ ~~~~~~~~~~~~~~~
Hi AWR_Android_SRC.
The library you say you need is part of the system library. It seems that the stm32 environment of Arduino IDE is not installed correctly. I can't reply any more.
hello ja2gqp !
i m interesting ...are you programming stm32 with usb to serial adapter or with something else ???
i have big problem with programming stm32 hi!hi!hi!
73 de 9a3xz
Hi Mikele.
I'm sorry that the answer is only for memory, because the development environment of stm32 is not already on the PC.
When I first started using stm32, I used ST-LINK V2. However, many people use serial adapters, so I started to use serial adapters.
If you use USB, you have to write bootloader. I also tested writing with USB, but gave up writing USB because the startup time of the firmware I wrote was long.
Writing using a serial adapter is the recommended method.
The setting of the jumper chip differs depending on the writing method. be careful.
Yes, many thanks...i will try with usb to serial ftdi. See you soon.all the best.
today i finally programming my Blue Pill and for testing conecting only tft display but not see anything on display ..can i conecting and other devices to Blue Pill to see on display ???
thanks in advance.
Hi Mikele.
Comment out the other device that uses I2C (si5351a). Since no response is returned from si5351a in I2C communication, it seems that nothing is displayed.
hmmm hmmm...now i conecting si5351 but nothing on the display.
i thinking,,,,whats the problem ?hi..hi
To Mikele.
I do not know that I2C communication is not working properly. Here are some stm32 samples. You can check the operation easily.
https://ja2gqp.blogspot.com/2017/06/stm32f103c8t6-base-bord.html
You can download the sample sketch from the stm32 folder here. The file name is stm32Example.zip.
OK THANKS.
tommorow i will try with:
Ucglib_ILI9341_18x240x320_HWSPI ucg(/*cd=*/ PB0 , /*cs=*/ PB10, /*reset=*/ PB1);
because now i very busy at work ;)))
for your information i have ,i using 2,4tft spi 240x320.
hello Akio !
blink working and si5351test working(from stm32example files) ,i put 100mhz (clk0) and listen signal on my radio,that is ok !
now i try 2,4 tft display.
To Mikele.
Congratulations on the operation of si5351.
Although it is a Japanese language, it is important to proceed step by step.
no...no working with Ucglogo
i conecting pb0(dc),pb1(rst) and pb10(cs)and vcc&led to 3,3v and gnd.
Akio maybe problem working on 1,8 tft but NOT on 2,4 tft ????
To Mikele.
Is the TFT controller ili9341 with SPI interface resolution 240x320?
I think either 1.8" or 2.4" will work with SPI of controller ili9341.
i bought tft like this:
https://www.ebay.com/itm/2-4-TFT-SPI-240x320-LCD-Serial-Port-Module-3-3V-PCB-Adapter-SD-ILI9341/163369059688?_trkparms=ispr%3D1&hash=item26098e0568:g:LDkAAOSwPPpb6P3f&enc=AQAFAAACcBaobrjLl8XobRIiIML1V4Imu%2Fn%2BzU5L90Z278x5ickkfOCvCjTOBWK8pwriaolq5iI7Q5BCovZ8ZY2n3JffSUyVLO%2BTB33Lryo%2F0MjxUcJVJJh0KMmF60I7RhfYaGyiWSBw%2BI1Kq4%2BwFSV%2FKZQxHBBvKOdlHgaMlCAheSUXrzJMTCD2o9j86cUyc2UqTGD8scaidSOpSOnPmB2jjBvkwfx42Vua7KjJVuPu0GsP3b9mhBupgLW20Gx%2FrA1BFiEkB0qtVWcfn3HoSG34FfOlMxx9%2Bk87%2BP%2B8pVIRwGXvxuVno3Q%2FbCFbvKYaSvZkCSt3oa35gbqLuXMNHZu9QqCBQbyQr%2FWNsMJ313q6gDazRfIyxcdqP1geWQXGIkKcyiodjQUbqcWIC%2BZy3%2Bu%2B0GfhzKB3xIWpV5CNZTGx7CZ3Sg5xEo2SUK6fp5jARmftjojNs9Hd3Dag8pkEHA4BdkBMTtCC0drYlLpOw35nV6aWdrvf35qPPC12ZFpeXuGAAIk7j3OEN53ArvNduuYV0CEiyffwYKYd2Oh%2BHGxQQdAoo1a20X5krbVnmL7CB2sm35S8Idq%2F8Rx8X3kYGYJbiMM7wXqbKfFlUcIew1%2FBlCAI6mhfedYG69of48NeQhg4rQo2h5XLdXOoHo8RURzbf0CYV%2FI8FaQVmScLF4eXzB2EkBixq4U8RWYX2RlydxD9cHOMuIyJwZDlWSYUlbRSS0rGjixb0i81T1GQ2BHzmzR0STmleEXpvXFxfaA%2B96gFbFdR5tF8WtKGt8P7WHZQBR%2FoezOav%2FQB%2FiuW7NOYAjK0oUTzwQhFq77GfQTjqAoKG7phnA%3D%3D&checksum=163369059688b4dca32ce85a429e8d4ac8818f620e82
To Mikele.
There is no problem with the TFT specifications. If the signal is correct, it should be displayed, but I don't understand.
To Mikele.
Is the current consumption increased due to the larger display?
Did you measure the VCC voltage of the TFT when energized?
is ok voltage...3,3V !
very strange ...hi!hi!
To Mikele.
TFT connection requires 5 signals.
PB10-CS, PB1-RESET, PB0-DC, PA7(MOSI)-SDI(MOSI), PA5(SCK)-SCK
In addition to this, connect VCC and GND.
There are 7 wires in all.
To Mikele.
Backlight wiring VCC-LED is missing.
working ucglogo....
but in sketch dds NO.
I m NOT conecting si5351!!!
Good morning Mikele.
If you do not connect si5351, I2C will be unable to communicate. I2C error handling is insufficient, so TFT display may not be possible.
good morning Japan ;))))
here is 00:01 :)))
after last post i conecting si5351 but nothing !
i m very tired and i go to sleep.in the morning i check my conecting and we will see...good night and many many thanks for your help.
To Mikele.
Since TFT and si5351 operate individually, there is no problem in H/W.
Do you use the sketch that you downloaded and downloaded from JA2GQP's Download site?
https://sites.google.com/site/ja2gqp/
This is the stm32_si5351a.zip file in the stm32 folder.
If the TFT cannot be displayed in the sketch, it seems that there is a problem in the library.
Unzip stm32_si5351a.zip and you will find the following files and folders:
src folder, si5351a2.h, stm32_si5351a.ino, stm32_si5351a.jpg, stm32_si5351a.pdf
Please test in the unzipped state.
NO,NO working...i try this.
Akio,I m not software expert but i cant see in sketch define PB6 and PB7 ,is it normal,is it ok???
continue working on monday hi!hi!hi!
thanks very much.
To Mikele.
I forgot that Rotaly.h has been upgraded. Changed contents of src folder.
After downloading 9z3xz.zip from the download site, unzip it and use it.
https://sites.google.com/site/ja2gqp/
The src folder contains Rotaly.h for this sketch.
thanks Akio...in monday morning i try this because dds in my office.
Thanks once again,you are big friend.
Akio is hard to say but not working.
i dont know...what s the problem in my story hi!hi!hi!
To Mikele.
I have created 9a3xz.zip for you. Please download from here.
https://sites.google.com/site/ja2gqp/
To Mikele.
It's confirmed.
The display of the sample sketch TFT is OK.
Is the display in VFO sketch black or white?
Or does it mean that nothing is changed when the message is displayed and the encoder is turned?
display is white...!
i with simple sketch tft is ok ,but i see text only in left up corner of display.
To Mikele.
OK.
I think unzipping 9a3xz.zip should fix the problem. please confirm.
sorry i cant see 9a3xz.zip file !
i only see in stm32 directory stm32_si5351a.zip new Rotary file in src.
To Mikele.
The latest version of stm32_si5351a.zip in the stm32 folder is OK on August 15, 2020.
very bad news...
my stm32 stop working after many test hi!hi!hi!
now time out about 15 days untill new stm32 arrive!
uf uf..uf.
i see just one thing..my Blue Pill was 20k ram and 128k flash NOT 64k
but never mind hi!hi!
thanks for all Akio..see you soon.
To Mikele.
It's too bad.
Resting your head will give you good results.
Akio....have good news.
my friend give me one second hand blue pill
now i try this of ja2nkd and working !!!
https://ja2nkd.blogspot.com/2016/11/dds-vfo-contoroller-by-stm32-arduino.html
but also i must said that i resoldered pins of tft display.
now....i m testing your dds.
Akio...i have no luck.
not working ...!
To Mikele.
I did a confirmation test, but the sketch works normally as shown in the circuit diagram.
It is said that the TFT is white, but the jumper settings are different at writing and at startup. When the program is started, both jumpers on the STM32 board are on the 1 side. When the jumpers are not set correctly, the TFT will be white.
no,no...boot jumpers is ok.
私はあきらめません
hi!hi!hi!
To Mikele.
This is the problem in my experience.
I wonder why it doesn't work.
Let's do our best to solve it.
there is one strange thing with my stm32...
when i programming your sketch .green led blinking always...in others sketches NOT !!
To Mikele.
There are two LEDs. One of them is a power supply display and the PWR display on the PCB lights green. The other one is red and connected to PC13. PC13 is a transmission signal. When PC13-GND is connected, it becomes a transmission state.
To Mikele.
Is the power circuit okay?
Supply the power supply voltage of 13.8V to +5V of STM32 by using 7805. 3.3V is made by the STM32 board, so it is taken from +3.3V of STM32.
yes ,yes ok.that is ok because this sketch working.
https://ja2nkd.blogspot.com/2016/11/dds-vfo-contoroller-by-stm32-arduino.html
Try commenting the next line with //.
Line 114
// timepassed = millis();
Line 229 to Line 234
// if((flg_frqwt == 1) && (flg_bfochg == 0)){ // EEPROM auto save 2sec
// if(timepassed+1000 <millis()){
// bandwrite();
// flg_frqwt = 0;
// }
//}
What is the display?
To Mikele.
Commenting millis() didn't improve anything. No confirmation required.
It works according to Blog's circuit diagram. However, as the sketch shows, Rotaly.h is included in the src folder as in the email.
The green LED (PWR) remains lit when writing a sketch. The LED never blinks.
i dont understand very well..
i commenting line 114 and 229-234 or NOT ???
To Mikele.
Modification of sketch is canceled.
Do nothing.
finally i m finished!!
all working good..afternoon i show you my video on YT.
Many thanks once agaim dear friend.
73 de 9a3xz Mikele
https://youtu.be/VfZrgj2asnU
https://youtu.be/VfZrgj2asnU
Hi,Mikele.
Congratulations on the completion.
POZDRAV
Izradio sam Vaš STM32-si5351 vfo .
Želim promijeniti IF na 9.000 Mhz.
Kako da to uradim promjenom u softveru?
@Mikele
What did you do to fix the issue please?
I downloaded stm32_si5351a.zip from the download site and checked if the sketch contains comments.
The question has no comments and is as per the original.
i haven't changed anything.
Is there a way you can send a hex file please. Does is matter if I use stlink to program?
I used to write using ST-LINK.
Most people use USB serial.
I also use USB serial unless there is a reason.
Writing to the board has different jumper settings.
Please refer to this.
https://en2gqp.blogspot.com/2017/01/stm32duino.html
Have come back after purchasing a new stm32f103c8t6 blue pill, a new si5351, and a new 240 by 320 SPI display with all the correct pinouts. Have added 3 buttons each for band, rit, and mode. The step is on the encoder button.
I am programming it through serial.
Downloaded the sketch again.
Uploaded to STM32 MC.
No display
After commenting out lines below the display is working but not saving to EEPROM flash. and the bands or channel does not work. In any case, it does not work at all when just uploading the sketch as provided.
145 - 166
229 - 234
I changed the sketch to refer to the src folder for EEPROM.h of the library I am using. Download the file Ver1.04.zip from the download site.
The src folder contains EEPROM.h.
Compile and write the sketch and it will work. Of course, the operation has been confirmed.
This time, the binary output file is also included. However, it is a BIN file, not a HEX file.
This time, there is a problem with your operating environment. You have to work this out yourself.
Once again, there is a problem with your operating environment.
Hello,
Thank you for trying to help me out . I very much appriciate it.
I have uploaded the BIN file to the microcontroller. That went fine.
The results are the same as when uploading the sketch through Arduino IDE version 1.18.6.
Once the BIN file or Sketch has loaded, the screen refreshes from white to black.
Blue C13 LED starts to flash and does not stop.
Backlight is on.
nothing on screen.
No output on CLK0 of si5351
I have checked that my wiring is correctg for the display and it is.
si5351 is also corrected wired.
Could it be that i have thw wrong version and or type of stm32f103C8t6
On my stm32 there is a red PWR light which is on always when board is powered up and a flashing blue light. This starts to flash and never stops.
I have resolved the issue and all is working as expected. I will implement this into a receiver project that I will begin for HF. This way i can use the VFO and BFO into the new receiver. Thanks for you help.
@Zaffars - Please let us know: how did you solve the problem?
i don't understand what you are saying
Hello, I made this project quite a long time ago. In my case, however, there is a problem. The display delays by about 5 seconds. I thought it was the fault of STM32 so I bought 3 more pieces. However, nothing has changed. When I turn the encoder, the display changes after 3-5 seconds. It is the same with the key operation. The changes are after a few seconds. Can I ask for advice on what I can do because I can't and the blog didn't find advice. Greetings - Tadeusz sp3vpa.
Translated with DeepL.com (free version)
It was a project about 7 years ago, so I have forgotten most of it.
From the symptoms, it seems that there is a problem with the encoder interrupt.
It has only been updated once since its development.
Please download Ver1.04.zip in the stm32 folder of the download site and try using it.
Thank you for your reply. I'm using ver.1.04 all the time, I also tried different versions of Arduino but without success. As I wrote with a delay also work buttons "MODE" "RIT" "BAND" "STEP". It seems as if the STM32 freezes for 5 seconds and after each operation.
Thank you for your willingness to help. I will try some more. If there is no result I will postpone the project. I wish you health and greetings. Tadeusz.
Translated with DeepL.com (free version)
Hi, I understand that this is now 7 years old. But I must say it's a fantastic VFO. I am currently building a 3 Band SSB Transceiver using this project. Everything is working well except the RIT. When I select RIT and using the rotary encoder the RIT display works fine (Adjusts up and down) But I get no change in the Si5351 output Frequency, hence no RIT.
Have you seen this before? Any ideas on how I can get this to work?
Thanks again for an amazing project.
73 (VK4ABZ)
VK4ABZ OM
Since this is a 7 year old project, I can't check it unless I set up the development environment.
Please wait for a while until the development environment is created.
VK4ABZ OM
Operation was confirmed using Ver1.04.
There is no problem with the question.
No problem at all.
LZ2IX
Hello guys, I would like to do the project. Unfortunately, the browser tells me that the folder with the archive from the link does not exist.
https://sites.google.com/site/ja2gqp/
Download stm32_si5351a.zip
How can I download the software? I want to program it with STM32CubeMX
Best regards 73!
It's been years since then, but the download site has moved here: https://sites.google.com/view/ja2gqp
I've never used STM32CubeMX, so I can't comment.
コメントを投稿