RF Frequency with an overclocked STM32 Bluepill

Started by Pippsen14, November 27, 2019, 11:17:03 AM

Pippsen14

Hello all,

I hope someone can give me a hint what's going wrong with my setup. On the regular way I can receive data with a STM32duino and a CPU Speed of 72MHz but if I overclock the CPU to 128MHz my RF Frequency is the half(216.5 MHz) of the adjusted 433MHz and no receiving is possible. The 216.5 MHz I got with the "getFrequency" command from the library. Provides the STM32 information's to the RFM69 board?  Which Values and register I can tune for correct working?

Appreciate your recommendations!


Felix


Pippsen14

Hi Felix,
Thank you for the fast reply. The SPI Clock was around 18MHz at a CPU Speed of 72Mhz and 32Mhz at a CPU Speed of 128MHz. I had tried to setup a good prescaler to fit the requirement of <= 10Mhz. Unfortunately this doesn't work, if I call the RFM69 Library and the Clock speed is a fourth of the CPU speed. In case I do only use the SPI Library and Functionality the different prescalers work without any problems.
Attached you will find my code:

#include <RFM69.h>         //get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPI.h>           //included with Arduino IDE install (www.arduino.cc)

#define NODEID      99
#define NETWORKID   100
#define GATEWAYID   1
#define FREQUENCY     RF69_433MHZ
#define ENCRYPTKEY    "sampleEncryptKey" //has to be same 16 characters/bytes on all nodes, not more not less!
#define IS_RFM69HW_HCW  //uncomment only for RFM69HW/HCW! Leave out if you have RFM69W/CW!
#define SERIAL_BAUD 115200
#define SPI1_NSS_PIN PA4    //SPI_1 Chip Select pin is PA4. You can change it to the STM32 pin you want.
  
RFM69 radio;

int TRANSMITPERIOD = 300; //transmit a packet to gateway so often (in ms)
byte sendSize=0;
boolean requestACK = false;
long lastPeriod = -1;
byte data;

typedef struct {
  int           nodeId; //store this nodeId
  unsigned long uptime; //uptime in ms
  float         temp;   //temperature maybe?
} Payload;
Payload theData;



void setup() 
{
  
  // Setup SPI 1
  SPI.begin(); //Initialize the SPI_1 port.
  SPI.setBitOrder(MSBFIRST); // Set the SPI_1 bit order
  SPI.setDataMode(SPI_MODE0); //Set the  SPI_1 data mode 0
  SPI.setClockDivider(SPI_CLOCK_DIV32);      // Slow speed (72 / 16 = 4.5 MHz SPI_1 speed)
  pinMode(SPI1_NSS_PIN, OUTPUT);
  
  Serial.begin(SERIAL_BAUD);

  // uncomment the next 3 lines and it work otherwise you get always a fourth of CPU Speed
  radio.initialize(FREQUENCY,NODEID,NETWORKID);
  radio.setHighPower(); //must include this only for RFM69HW/HCW!
  radio.encrypt(ENCRYPTKEY);
  
  char buff[50];
  sprintf(buff, "\nTransmitting at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
  Serial.println(buff);
}


void loop() 
{
   sendSPI();
 /* //process any serial input
  if (Serial.available() > 0)
  {
    char input = Serial.read();
    if (input >= 48 && input <= 57) //[0,9]
    {
      TRANSMITPERIOD = 100 * (input-48);
      if (TRANSMITPERIOD == 0)
      { 
        TRANSMITPERIOD = 1000;
      } 
      Serial.print("\nChanging delay to ");
      Serial.print(TRANSMITPERIOD);
      Serial.println("ms\n");
    }
    
    if (input == 'r')//d=dump register values
    {  
      radio.readAllRegs();
    }
  }
  
  int currPeriod = millis()/100;
  if (currPeriod != lastPeriod)
  {
    //fill in the struct with new values
    theData.nodeId = NODEID;
    theData.uptime = millis();
    theData.temp = 91.23; //it's hot!
    
    Serial.print("Sending struct (");
    Serial.print(sizeof(theData));
    Serial.print(" bytes) ... ");
    if (radio.sendWithRetry(GATEWAYID, (const void*)(&theData), sizeof(theData)))
    {
      Serial.print(" ok!");
    }
    else 
    { 
      Serial.print(" nothing...");
    }     
    Serial.println();
    Blink(LED_BUILTIN,3);
    lastPeriod=currPeriod;
  }*/
}

void Blink(byte PIN, int DELAY_MS)
{
  pinMode(PIN, OUTPUT);
  digitalWrite(PIN,HIGH);
  delay(DELAY_MS);
  digitalWrite(PIN,LOW);
}

void sendSPI()
{
  digitalWrite(SPI1_NSS_PIN, LOW); // manually take CSN low for SPI_1 transmission
  data = SPI.transfer(0x55); //Send the HEX data 0x55 over SPI-1 port and store the received byte to the <data> variable.
  digitalWrite(SPI1_NSS_PIN, HIGH); // manually take CSN high between spi transmissions
}



Pippsen14

Good news, found the prescaler value within the cpp file and changed it. Is there a chance to get it from outside?

Felix