//I2C
void i2cSendRegister(char reg, char data_) {
char bufer[2] = {reg, data_};
while (HAL_I2C_Master_Transmit(&hi2c3, I2C_WRITE, (uint8_t *) &bufer, (uint16_t) 2, (uint32_t) 500) != HAL_OK) {
};
}
// Set up specified PLL with mult, num and denom
// mult is 15..90
// num is 0..1,048,575 (0xFFFFF)
// denom is 0..1,048,575 (0xFFFFF)
//
void setupPLL(char pll, char mult, unsigned long num, unsigned long denom) {
unsigned long P1; // PLL config register P1
unsigned long P2; // PLL config register P2
unsigned long P3; // PLL config register P3
P1 = (unsigned long) (128 * ((float) num / (float) denom));
P1 = (unsigned long) (128 * (unsigned long) (mult) + P1 - 512);
P2 = (unsigned long) (128 * ((float) num / (float) denom));
P2 = (unsigned long) (128 * num - denom * P2);
P3 = denom;
i2cSendRegister(pll + 0, (P3 & 0x0000FF00) >>
;
i2cSendRegister(pll + 1, (P3 & 0x000000FF));
i2cSendRegister(pll + 2, (P1 & 0x00030000) >> 16);
i2cSendRegister(pll + 3, (P1 & 0x0000FF00) >>
;
i2cSendRegister(pll + 4, (P1 & 0x000000FF));
i2cSendRegister(pll + 5, ((P3 & 0x000F0000) >> 12) | ((P2 & 0x000F0000) >> 16));
i2cSendRegister(pll + 6, (P2 & 0x0000FF00) >>
;
i2cSendRegister(pll + 7, (P2 & 0x000000FF));
}