Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library reports dev_status even when device is not present #74

Open
radio-miskovice opened this issue May 2, 2020 · 0 comments
Open

Comments

@radio-miskovice
Copy link

I have a program that initializes CLK0, sets frequency and then it periodically reads device status, and sends some results to Serial.

It appears that even when I remove the Si5351 module, the program still reads some "status" (LOL_A = 0);

Expected behavior
I would expect some kind of error, to recognize the device is not present.

Code

#include <Wire.h>
#include "si5351.h"

/* Si5351 module */ 
#define VFO SI5351_CLK0 
uint64_t vfoFreq = 702130000ULL ;
bool vfoOk = false ;
Si5351 vfo ;

void setup() {
  uint8_t idev ;
  uint16_t dw ;
  // blinker & serial //
  pinMode( PC13, OUTPUT );
  digitalWrite( PC13, LOW );
  Serial.begin(115200);
  delay(10);
  Serial.println("started.");
  digitalWrite( PC13, HIGH );
  // I2C setup 
  // Wire.setSDA(PB9);
  // Wire.setSCL(PB8);
  Wire.begin();
  Serial.println("I2C bus on PB8, PB9");  
  Si5351A initalization 
  Serial.print("Si5351 ");
  if( checkI2C( 0x60 ) != 0 ) Serial.println("not ");
  Serial.println("present");  
  vfoOk = vfo.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0) ;
  Serial.println( vfoOk ? "VFO OK" : "VFO ??" );
  vfo.set_freq( vfoFreq, VFO );  
  vfo.update_status();
  delay(1000);
}

uint8_t lastPllA = 0xFF ;
void loop() {
  Si5351Status st = vfo.dev_status ;
  vfo.update_status();
  if( st.LOL_A != lastPllA ) {
    Serial.printf( "VFO PLL A: %i\n", st.LOL_A ); 
    lastPllA = st.LOL_A ;
  }
  digitalWrite( PC13, LOW );
  vfo.output_enable( VFO, false );
  delay( 200 ); 
  readSerial();
}

void readSerial() {
  char text[40] = { 0 };
  byte inputSize = 0 ;
  if( Serial.available() ) {
    digitalWrite( PC13, HIGH );
    delay(100);
    inputSize = Serial.readBytesUntil( '\n', text, 39 );
    if( inputSize ) text[inputSize] = 0;
    Serial.print( "ECHO: "); Serial.println( text );
    delay(65);
    digitalWrite( PC13, LOW );
  }
}

uint8_t checkI2C( uint8_t addr ) {
  Wire.beginTransmission( addr );
  return Wire.endTransmission();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant