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

Simple test for beginner with ESP32 and si5351 (with a M5StackStickCplus) #3

Open
robouden opened this issue Dec 21, 2022 · 6 comments

Comments

@robouden
Copy link

Sorry to bother, but it seems you are one of the few that got the ESP32 and the si5351 working nicely.
After downloading and looking at your code, I was trying to find out how to simply the code for my M5StackStickCplus to work. But I could not figure that out.to get the I2C working on pin G26 (SCL) and pin G0(SDA).

Please advise me how to make a simple .ino file with the modified libraries you made (Ii2c.h and si5351.h)

Regards,
Rob Oudendijk

@paulh002
Copy link
Owner

Hello Rob,

This repository is a bit older and the solution I used was to implement my own simple I2C functions. If you create the SI5351 class you can specify the SCL and SDA pins. Si5351::Si5351(uint8_t i2c_addr, uint8_t i2c_sda, uint8_t i2c_scl). In the file IO.CPP you can see the definition for the ports.

-------------------------------------------------------
Si5351
--------------------------------------------------------
/

#define I2C_SDA2 16
#define I2C_SCL2 17
#define SI5351_XTAL_FREQ1 SI5351_XTAL_FREQ //25 mhz
//#define SI5351_XTAL_FREQ1 32000000

#define CLK_BFO_RX SI5351_CLK2
#define CLK_VFO_RX SI5351_CLK2
#define CLK_BFO_TX SI5351_CLK0
#define CLK_VFO_TX SI5351_CLK0
#define CLK_NA SI5351_CLK1

Si5351 si5351;
Si5351 si5351_bfo(SI5351_BUS_BASE_ADDR, I2C_SDA2, I2C_SCL2);

In the meantime there is a fix for the SI5351 library (https://github.com/etherkit/Si5351Arduino) but the maintainer did not implement it.
You have to change the SI5351::si5351_read method

Change Wire.requestFrom(i2c_bus_addr, (uint8_t)1, (uint8_t)false);

to Wire.requestFrom(i2c_bus_addr, (uint8_t)1); //, (uint8_t)false);

Than you can use the original library

@robouden
Copy link
Author

Whooo, thank you so much for the fast reply.
I will check tomorrow and report back to you.

Warm regards,
Rob Oudendijk

@robouden
Copy link
Author

Paul,

Just before going to bed. Tried the modifications you mentioned.
Worked great!! Now very simple code.

/*



*/
#include "M5StickCPlus.h"
#include "si5351.h"
#include <Wire.h>

Si5351 si5351;

void setup() {
bool i2c_found;
// Start serial and initialize the Si5351
Serial.begin(9600);
i2c_found = si5351.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);

M5.begin();
// Lcd display
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(10, 10);
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setTextSize(2);
M5.Lcd.setRotation(3);
delay(500);

//Check I2C
if(!i2c_found)
{
M5.Lcd.setTextColor(RED);
M5.Lcd.println("Error on I2C bus!");
}
else {
M5.Lcd.println("si5351 on I2C bus!");
}

delay(1000);
// text print
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(10, 10);
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setTextSize(2);
M5.Lcd.setRotation(3);
M5.Lcd.println("Si5351 test");
M5.Lcd.println();

// Set CLK0 to output 27.12 MHz
si5351.set_freq(2712000000ULL, SI5351_CLK0);
M5.Lcd.println(" CLK0 =27.12MHz");

}

void loop() {

}

@robouden
Copy link
Author

IMG-0045

Output from si5351 with new code at 27.12MHz

@paulh002
Copy link
Owner

Great that it works!

@robouden
Copy link
Author

And here the M5StickCPlus and the Si5351.
IMG-0044

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

2 participants